I have a series of task that accept data then when finished processing move it to a different task.
Each task has its own Executor Service initialized as
int workerSize = Runtime.getRuntime().availableProcessors() * 2;
executorService = new ThreadPoolExecutor(workerSize, workerSize,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(),
new SongKongThreadFactory(threadGroup));
The tasks work on files each file get put on taskA queue, then when processed by taskA it may be put on taskB's queue or straight onto taskC queue.
One aim of this pipeline approach is that however many files you have the application doesnt use too much memory because only some files are being processed at any time, however each tasks has different throughput levels so Im finding that the task B queue is building up because files are processed more quickly by task A then task B. And these queues are using memory
So I changed executor servide defn to specify a amx size of the queue as follows:
executorService = new ThreadPoolExecutor(workerSize, workerSize,0L, TimeUnit.MILLISECONDS,new LinkedBlockingQueue<Runnable>(100),
new SongKongThreadFactory(threadGroup));
My idea was that if task A tried to submit the 101 item then it would just wait until there was a space, so processing on task A would temporarily sleep and memory usage would be reduced. But instead the task just gets rejected with RejectedExecutionException .Ive since checked all the available ThreadExecutor policys and none just allow the calling process to wait.
So i think I must be approaching this in the wrong way, how should I be doing this ?
I'm currently using Java 7 and expect to move to Java 8 when released.