I'm using a FixedThreadPool for worker threads. Here's how I created it:
ThreadPoolExecutor producerThreadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(25);
So I set the size of it as 25, I assume there should only be at most 25 active threads at any time? (correct me if I'm wrong).
Then my main thread is constantly trying to submit 30 worker threads at a time if there are idle threads in the thread pool:
if(producerThreadPool.getActiveCount() <= 25)
but when I debug it I got this log:
Mon Jul 23 14:04:42 EDT 2012: {"queued_count":"0","active_count":"28","scheduled_tasks":"28","core_pool_size":"1000","pool_size":"29"}
Mon Jul 23 14:04:43 EDT 2012: {"queued_count":"0","active_count":"3","scheduled_tasks":"33","core_pool_size":"1000","pool_size":"34"}
Mon Jul 23 14:04:44 EDT 2012: {"queued_count":"0","active_count":"0","scheduled_tasks":"60","core_pool_size":"1000","pool_size":"60"}
Mon Jul 23 14:04:45 EDT 2012: {"queued_count":"0","active_count":"0","scheduled_tasks":"90","core_pool_size":"1000","pool_size":"90"}
...
Queue is always empty, core_pool_size is still 1000, and pool_size is keep increasing till 1000, but I assume that core_pool_size should be 25 and there should be queued tasks?
Did I do something wrong or misunderstand this?
Any help would be appreciated, thank you!
This is how I generated the log:
HashMap<String, String> log = new HashMap<String, String>();
log.put("core_pool_size", Integer.toString(producerThreadPool.getCorePoolSize()));
log.put("scheduled_tasks", Long.toString(producerThreadPool.getTaskCount()));
log.put("pool_size", Integer.toString(producerThreadPool.getPoolSize()));
log.put("active_count", Integer.toString(producerThreadPool.getActiveCount()));
log.put("queued_count", Integer.toString(producerThreadPool.getQueue().size()));
String gson_str = gson.toJson(log);