Class that extends from Thread and I have two or more them running, they have their own queus to work on with.
When the queue is in some point empty then sometimes I want them to pause because thread that fills their queue is in Thread.WAITING state.
When the first thread whose queue is empty calls method that causes it to wait e.g.
Now the first thread calls this succesfully, but second and other same class instances of this thread never gets this far, so are they in WAITING state too when the first does the pause call. They all have different names.
I have struggled with the synchronization for a long time now, to avoid consumption of memory (heap is setted to ~300MB or more) and be fast as it can be. With these classes I am comparing number permutations and there can be billion of them and it takes ages to process those
Okay, I was looking for an answer to this question, posted earlier:
"(Are there) Two or more different instances (of the AbstractDataProcesser) or two or more Threads running the same instance of the class?"
The answer to that question seems to be in the createDataProcessers() method which you don't show.
So: Is there just one instance of the AbstractDataProcesser created, and inserted into the array of processers which gets run, or do you create one instance of AbstractDataProcesser, put it into the array twice, and then run both instances?
If there are multiple instances, then you should have to worry about synchronizing processing inside AbstractDataProcessor, and the error probably lies in the dataLoader, and the sharing of values between different threads inside that class (paused state, etc...). If there is one instance of the AbstractDataProcesser then we have to look at the data inside AbstractDataProcesser, since it is NOT thread safe, as well as the synchronization of methods. What is happening inside dataLoader is important too - but the narrowest focus first, we would need to make sure ADP is thread safe first, then expand out to the dataLoader.
Joined: Dec 13, 2008
So I should remove ADL from ADP's and program ADL so that it informs ADP's when everything should pause and when loading data to its queue is paused then ADP fires an event when it needs more, etc.
Firing events probably eats too much memory...
abdulrub bin mohsin wrote:how threads are communicates in java.
Hi Abdulrub, this is a different question than what the OP was asking, so you should probably ask it in its own thread. It will attract more attention, won't detract from the previous conversation, and won't cause confusion.