Java: serial thread confinement question
Posted
by denis
on Stack Overflow
See other posts from Stack Overflow
or by denis
Published on 2010-05-08T20:10:46Z
Indexed on
2010/05/08
20:18 UTC
Read the original article
Hit count: 231
Assume you have a Collection(ConcurrentLinkedQueue) of Runnables with mutable state. Thread A iterates over the Collection and hands the Runnables to an ExecutorService. The run() method changes the Runnables state. The Runnable has no internal synchronization.
The above is a repetitive action and the worker threads need to see the changes made by previous iterations. So a Runnable gets processed by one worker thread after another, but is never accessed by more than one thread at a time -> a case of serial thread confinement(i hope ;)).
The question: Will it work just with the internal synchronization of the ConcurrentLinkedQueue/ExecutorSerivce?
To be more precise: If Thread A hands Runnable R to worker thread B and B changes the state of R, and then A hands R to worker thread C..does C see the modifications done by B?
© Stack Overflow or respective owner