Steve Luke wrote:
But in practice, using an ExecutorService (like the ThreadPoolExecutor) will do this sort of queuing and distribution for you, and also maintains the threads. So you should probably just consider using one of those.
And executors generally does what is most efficient, and not exact fine grain control. For example...
Santosh Kumar Nayak wrote:Scenario:-
There are 2 threads A and B
There are tasks like T1,T2,T3,T4 ....T10
How to put the logic such that A processes T1 , then B processes T2, then A processes T3 , then B processes T4 and so on...
If an executor has two threads (say A and B), then A will get T1 and B will get T2. However, if
thread B finishes processing first, it will not wait for thread A, it will go get the next task, T3, and process that. By default, there won't be interlacing of threads and tasks.
Henry