Java MultiThreading Code Error
<p>I am trying to learn multithreading execution in Java. Now, I have a code like:</p>

<pre><code>class ThreadDemo {
public static void main(String args[]) {
   try{

   int [] arr = new int[10] ;
      for(int i = 0 ; i &lt; 10 ; i++)
         arr[i] = i ;

   for(int c =0 ; c &lt; 2 ; c++){
         for(int i = 0 ; i &lt; 3 ; i++) //I want to run it on one thread
             System.out.println(arr[i]);
         for(int j = 0 ; j &lt; 5 ; j++)  //I want to run it on another thread
             System.out.println(arr[j]);
            }

} catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
    }
   }
}
</code></pre>

<p>Now, to solve this I have tried,</p>

<pre><code>class ThreadDemo {
public static void main(String args[]) {
try{

int [] arr = new int[10] ;
for(int i = 0 ; i &lt; 10 ; i++)
arr[i] = i ;

    for(int c =0 ; c &lt; 2 ; c++){
         Thread thread1 = new Thread () {
         public void run () {
         for(int i = 0 ; i &lt; 3 ; i++) //I want to run it on one thread
           System.out.println(arr[i]);}
          };

          Thread thread2 = new Thread () {
          public void run () {
          for(int j = 0 ; j &lt; 5 ; j++) //I want to run it on one thread
           System.out.println(arr[j]);}
          };


         }

} catch (Exception e) {
        System.err.println("Error: " + e.getMessage());
    }
   }
}
</code></pre>

<p>But gives error. Can anyone help me how to solve this ?</p>
