title: How JVM thread scheduler control threads for multiprocessors?
body: <p>I've been reading Head First for multithreading. What I know about multithreading is: </p>
  
  <p>When we call <strong>start()</strong> with an object of <strong>Thread</strong> class that thread goes to the <strong>Runnable</strong> state. So all the threads go to <strong>Runnable</strong> state after calling <strong>start()</strong> by the object of those threads. It is <strong><em>JVM thread scheduler</em></strong>, who picks thread randomly from <strong>Runnable</strong> state to give it in <strong>Running</strong> state. After going to <strong>Running</strong> state, the determined call stack for that specific thread becomes executed. </p>
  
  <p>Again, JVM thread scheduler can stop the execution of a thread by picking that thread from Running state to Runnable state. This time, code execution is paused in the call stack of that thread. </p>
  
  <blockquote>
    <p>Now my question is, for multiprocessor machine, how JVM thread
    scheduler picks thread from the Runnable state? Does it pick only one
    thread and give it to a processor? Or, does it pick more than one
    thread and give those threads to Running state of different
    processors?</p>
  </blockquote>
  
  <p>I have written below code: </p>
  
  <pre><code>// Class of main thread
  public class ThreadMain {
  
      public static void main(String[] args) {
  
          Runnable threadJob=new MyRunnable();
          Thread t=new Thread(threadJob);
          t.start();
          System.out.println("Back in the Main");
      }
  }
  // Class of another thread
  public class MyRunnable implements Runnable{
  
      public void run()
      {
          System.out.println("I'm Thread");
      }
  }
  </code></pre>
  
  <p>Here, there are two threads. Main thread, and the thread I've created. If my machine has multiprocessor, how will it behave? Will the JVM thread scheduler pick two threads at a time, and give those to two processors?  </p>