title: Java threads to do different tasks?
body: <p>I am looking at an example which code is:</p>
  
  <pre><code>class SimpleThread extends Thread {
      public SimpleThread(String str) {
          super(str);
  }
  
  public void run() {
      for (int i = 0; i &lt; 10; i++) {
          System.out.println(i + " " + getName());
              try {
          sleep((int)(Math.random() * 1000));
          } catch (InterruptedException e) {}
      }
      System.out.println("DONE! " + getName());
      }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class TwoThreadsTest {
      public static void main (String args[]) {
          new SimpleThread("Jamaica").start();
          new SimpleThread("Fiji").start();
      }
  }
  </code></pre>
  
  <p>My question is: is there a way each thread does its own code? For example, one thread increments a variable, while the other thread increments other variable.
  Thanks.</p>
  
  <p>P.S. Example's link is: <a href="http://www.cs.nccu.edu.tw/~linw/javadoc/tutorial/java/threads/simple.html" rel="nofollow">http://www.cs.nccu.edu.tw/~linw/javadoc/tutorial/java/threads/simple.html</a></p>