From owner-freebsd-java Tue Oct 1 4:20:38 2002 Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DD99B37B401 for ; Tue, 1 Oct 2002 04:20:36 -0700 (PDT) Received: from smtp2.libero.it (smtp2.libero.it [193.70.192.52]) by mx1.FreeBSD.org (Postfix) with ESMTP id 71D7F43E65 for ; Tue, 1 Oct 2002 04:20:36 -0700 (PDT) (envelope-from toglikingdementortogli@yahoo.com) Received: from yahoo.com (151.25.174.171) by smtp2.libero.it (6.5.028) id 3D8B3DDE004A335C for freebsd-java@FreeBSD.ORG; Tue, 1 Oct 2002 13:20:32 +0200 Message-ID: <3D99524C.50605@libero.it> Date: Tue, 01 Oct 2002 09:44:12 +0200 From: Giulio Ferro User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.0.1) Gecko/20020923 X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-java@FreeBSD.ORG Subject: Wrong thread behavior Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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