Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 01 Oct 2002 09:44:12 +0200
From:      Giulio Ferro <aurynkid@libero.it>
To:        freebsd-java@FreeBSD.ORG
Subject:   Wrong thread behavior
Message-ID:  <3D99524C.50605@libero.it>

next in thread | raw e-mail | index | archive | help
Native jdk 1.3.1p7

If we consider the following snippet:

public class SimpleThread extends Thread {
  private int countDown = 50;
  private static int threadCount = 0;
  private int threadNumber = ++threadCount;
  public SimpleThread() {
    System.out.println("Making " + threadNumber);
  }
  public void run() {
    while(true) {
      System.out.println("Thread " +
        threadNumber + "(" + countDown + ")");
      if(--countDown == 0) return;
    }
  }
  public static void main(String[] args) {
    for(int i = 0; i < 5; i++)
      new SimpleThread().start();
    System.out.println("All Threads Started");
  }
} ///:~


You can notice that the execution never breaks out of run() unless you 
explicitly put a sleep() or yield().
It goes on any single thread until the thread returns without 
automatically switching to the others.



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-java" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D99524C.50605>