In the common workQueue , theadPoolExecution architecture , when a job arrives , only one thread is invoked and that thread completes the work.
Instead i want all threads to be invoked and all the threads to perform the task.
My scenario is as below.
I have 5000 data items and i have to run a task on each data item. Running it one by one has proved slow , hence i want to use threading here.
Here lets say i employed 5 threads. The first thread will execute the first 1000 data items , the second will execute the next 1000 and other will follow.
Now when a job arrives which needs to be executed on this 5000 data items , all the 5 threads have to be invoked or rather put back from sleep , so that it can perform its task.
How is this possible using theadPoolExecution in java.
I am aware that inserting 5 copy of the same job to the queue might help.
But this has many side effects like if a thread quickly completes its job , it will take up someone else work.
Thanks
Vineeth
Since you want first thread to process first 1000 items and the second thread process another 1000 items, this mean you want threads to execute different tasks. If, in contrast, all threads execute same task, this mean all threads execute the same data items (which is of no use and may cause problems when threads will save results into the same place).
So please, don’t do “inserting 5 copy of the same job”. Submit different tasks, with different data ranges.
Here in each pass of the loop, new task with different parameters is created and submitted to the executor.