I have a application in Java in which I need to use multi-threading.
I have a list of ID's which is primary key for tables stored in DynamoDB.
Say, the list is :
| ID_1 | ID_2 | ID_3 | ID_4|.......| ID_n|
Now I want multiple threads to read these ID's and do the following for each ID:
Each thread should take a ID and query DynamoDB tables (there are two dynamo DB tables for which ID is the primary key)
The result of querying each Dynamo DB table should be stored in a separate file.
Essentially, Thread_1 should pick up a ID say ID_1, it should query DynamoDB tables DDB_1 and DDB_2. The result of querying DDB_1 should go in File1 and result of DDB_2 should go in File_2. This needs to be done for all the threads. Finally, when all threads have completed execution I should have two files File_1 and File_2 containing results of query from all the threads.
I have come up with a solution that let all producer threads (threads which get the query results from Dynamo DB) queue the results of the query to a single consumer thread which writes to a file say File_1. Similarly all producer threads write to a second queue and a second consumer thread writes to File_2.
Do you feel any flaw in the approach above? Is there a better way to apply multi-threading in this case?