JAVA: 500 Worker Threads, what kind of thread pool?

Posted by Submerged on Stack Overflow See other posts from Stack Overflow or by Submerged
Published on 2010-05-19T18:24:33Z Indexed on 2010/05/19 18:30 UTC
Read the original article Hit count: 254

Filed under:
|
|

I am wondering if this is the best way to do this. I have about 500 threads that run indefinitely, but Thread.sleep for a minute when done one cycle of processing.

   ExecutorService es = Executors.newFixedThreadPool(list.size()+1);
   for (int i = 0; i < list.size(); i++) {
      es.execute(coreAppVector.elementAt(i)); //coreAppVector is a vector of extends thread objects
   }

I do need a separate threads for each running task, so changing the architecture isn't an option. I tried making my threadPool size equal to Runtime.getRuntime().availableProcessors() which attempted to run all 500 threads, but only let 8 (4xhyperthreading) of them execute. The other threads wouldn't surrender and let other threads have their turn. I tried putting in a wait() and notify(), but still no luck. If anyone has a simple example or some tips, I would be grateful!

© Stack Overflow or respective owner

Related posts about java

Related posts about threads