Duplicate :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
Name: vi73552 Date: 04/14/99 1. Exact steps ... 1) Create a thread group. 2) Add some threads to it. 3) Start some of them. 4) Get active Thread count. 5) Get enumeration of ThreadGroup. 6) Step through the enumeration and start the ones that return false for isAlive. You can't do this on Java 1.2 because the enumeration only returns the threads that return true for isAlive. 2. Java SOURCE CODE ... ThreadGroup tg = new ThreadGroup("group1"); //*0 Thread[] t = new Thread[3]; t[0] = new Thread(tg,r[0],"thread"+0); //*1 t[1] = new Thread(tg,r[1],"thread"+1); t[1].start(); //*2 t[2] = new Thread(tg,r[2],"thread"+2); //*3 int count = tg.activeCount(); Thread[] a = new Thread[count]; int active = tg.enumerate(a); for (int ndx = 0; ndx < active; ndx++) if (!active[ndx].isAlive()) active[ndx].start(); else System.out.println("Thread already alive: " + active[ndx]); But this will only display that thread1 is already alive, and thread0 and thread2 will never get started. 5. The out put of commands ... java version "1.2" Classic VM (build JDK-1.2-V, native threads) java full version "JDK-1.2-V" (Review ID: 56516) ====================================================================== Name: boT120536 Date: 01/30/2001 java version "1.3.0" Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C) Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode) ThreadGroup tg=new ThreadGroup("unstoppable"); Thread t1=new Thread(tg,"thread1",runnable1); Thread t2=new Thread(tg,"thread2",runnable2); t1.start(); while (t1.isAlive()) try {Thread.sleep(1000);} catch (Throwable t) {;} try { tg.stop(); } catch (IllegalThreadStateException itse) { /* This is because t2 has not been started, and cannot be disposed() */ System.err.println("Expected Exception occured:"); itse.printStackTrace(); /* at this point you cannot enumerate which threads have not been started, and you cannot start them, enumerate them, discover anything about them. */ } catch (Throwable t) { System.err.println("This was an unexpected error:"); t.printStackTrace(); } One must be able to guarantee the JVM will properly terminate without requiring a call to System.exit(), or Runtime.exit(). In order to meet that requirement, all threads in existence must be daemon, and the JVM will examine _ALL_ threads. In Java, there is no reliable method to determine if System.exit() is required. There is no method available to see if there are any unstarted threads. Since the mechanism to get a full thread dump under program control was removed, this cannot be used to introspect the current state of the VM to determine if there are threads which have not been started, and thus determine if a System.exit() is required. When bugs are fixed, it is the nature of the problem, which determines what is implemented as a solution. In this particular case, I am concerned that the nature of the problem defined for Bug#4229558 will ignore the real problem. Sincerely, Ken Graham. (Review ID: 115893) ======================================================================
|