Trouble understanding Java threads
<p>I'm sorry in advance, I learned about multiprocessing from python and I'm having a bit of trouble understanding Java's approach.  In python, I can say I want a pool of 4 processes and then send a bunch of work to my program and it'll work on 4 items at a time.  I realized, with Java, I need to use threads to achieve this same task and it seems to be working really really well so far.  </p>

<p>But..I unlike in python, my cpu(s) aren't getting 100% utilization(they are about 70-80%) and I suspect its the way I'm creating threads(code is the same between python/java and proceses are independent).  In Java, I'm not sure how to create one thread so I create a thread for every item in a list I want to process, like this:</p>

<pre><code>    for (int i = 0; i &lt; 500; i++) {
        Runnable task = new MyRunnable(10000000L + i);
        Thread worker = new Thread(task);
        // We can set the name of the thread
        worker.setName(String.valueOf(i));
        // Start the thread, never call method run() direct
        worker.start();
        // Remember the thread for later usage
        threads.add(worker);
    }
</code></pre>

<p>I took it from <a href="http://www.vogella.de/articles/JavaConcurrency/article.html#threads" rel="nofollow">here</a> .  My question is this the correct way to launch threads or is there a way to have java itself manage the number of threads so its optimal? I, like everyone I guess, want my code to run as fast as possible and I'm trying to understand how to tell and resolve any issues that maybe arising from too many threads being created.  This is not a major issue, just curious to how it works under the java hood.</p>

<p>Thanks!</p>
