title: 500 Worker Threads, what kind of thread pool?
body: <p>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.</p>
  
  <pre><code>   ExecutorService es = Executors.newFixedThreadPool(list.size()+1);
     for (int i = 0; i &lt; list.size(); i++) {
        es.execute(coreAppVector.elementAt(i)); //coreAppVector is a vector of extends thread objects
     }
  </code></pre>
  
  <p>The code that is executing is really simple and basically just this</p>
  
  <pre><code>class aThread extends Thread {
     public void run(){
        while(true){
           Thread.sleep(ONE_MINUTE);
           //Lots of computation every minute
        }
     }
  }
  </code></pre>
  
  <p>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! </p>
  
  <p>Well, the design is arguably flawed. The threads implement Genetic-Programming or GP, a type of learning algorithm. Each thread analyzes advanced trends makes predictions. If the thread ever completes, the learning is lost. That said, I was hoping that sleep() would allow me to share some of the resources while one thread isn't "learning"</p>
  
  <p><strong>So the actual requirements are</strong> </p>
  
  <blockquote>
    <p>how can I schedule tasks that maintain
    state and run every 2 minutes, but
    control how many execute at one time.</p>
  </blockquote>