Multiple threads modifying a collection in Java??
Posted
by posdef
on Stack Overflow
See other posts from Stack Overflow
or by posdef
Published on 2010-04-29T10:05:21Z
Indexed on
2010/04/29
16:47 UTC
Read the original article
Hit count: 326
java
|multithreading
Hi,
The project I am working on requires a whole bunch of queries towards a database. In principle there are two types of queries I am using:
read from excel file, check for a couple of parameters and do a query for hits in the database. These hits are then registered as a series of custom classes. Any hit may (and most likely will) occur more than once so this part of the code checks and updates the occurrence in a custom list implementation that extends ArrayList.
for each hit found, do a detail query and parse the output, so that the classes created in (I) get detailed info.
I figured I would use multiple threads to optimize time-wise. However I can't really come up with a good way to solve the problem that occurs with the collection these items are stored in. To elaborate a little bit; throughout the execution objects are supposed to be modified by both (I) and (II).
I deliberately didn't c/p any code, as it would be big chunks of code to make any sense.. I hope it make some sense with the description above.
Thanks,
© Stack Overflow or respective owner