Note that there are some explanatory texts on larger screens.

plurals
  1. POThreadPoolExecutor threads having contention with other threads
    primarykey
    data
    text
    <p>I am working on a enhancement for an existing Java application. The application is a message processor which processes several millions of messages daily. It basically written using Core Java with threads and queues are implemented using Collection classes.</p> <p>In this application some type of the messages are running in a single thread. I was given the task to make this particular part of the application to multi threaded to process the messages faster, as we have dual processors. </p> <p>Since we are using Java 5, I took the approach of using ThreadPoolExcecutor. I have created processor threads for each clients so that message for a particular threads can be processed in its own thread. The processor threads are implementing Callable interface as this will allow me to check the future object whether the previous task is finished or not.</p> <p>During initialization process, I will go over all the clients and create processor threads for each and store it in map using their id as unique key. To track previously submitted job, I do keep the future object in another map again using same id as unique key.</p> <p>Below are some snippet of code which I used : In main class - </p> <pre><code>ThreadPoolExecutor threadPool = null; int poolSize = 20; int maxPoolSize = 50; long keepAliveTime = 10; final ArrayBlockingQueue&lt;Runnable&gt; queue = new ArrayBlockingQueue&lt;Runnable&gt;(1000); threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize,keepAliveTime, TimeUnit.SECONDS, queue); .... .... for (each client...) { id = getId().. future = futuremap.get(id); if(!future.isDone()) continue; if(future == null || future.isDone()) { processor = processormap.get(id); if(processor == null) { processor = new Processor(.....); //add to the map processormap.put(id,processor); } //submit the processor future = threadPool.submit(processor ); futuremap.put(id,future); } } </code></pre> <p>Processor Thread</p> <pre><code>public class MyProcessor implements Callable&lt;String&gt; { ..... ..... public String call() { .... .... } } </code></pre> <p><strong>The Issue</strong> </p> <p>The above implementation is working good in my test environment. However, in production environment (<strong>Edit#1</strong> - <strike>Ubuntu</strike>, Linux Slackware, Java - 1.6.0_18), we observed that other threads of the application which are not managed through this new ThreadpoolExecutor are getting affected. i.e., their tasks are getting delayed for hours. Is it because the threads created by ThreadPoolExecutors are taking the whole resources or whatsoever and not giving the chance to other threads. </p> <p>The new threads created using ThreadPoolExceutor are doing independent task and are not in contention with other thread for resources. i.e., there is no race condition scenario. </p> <p>In the log, for the new Threads, I can see that there are maximum of 20 threads running (corepoolsize) and there are no rejection exceptions, i.e., the number of submits are within the bounds of the queue. </p> <p>Any ideas why this is happening? </p> <p>Thanks in advance. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload