test/java/util/Timer/KillThread.java

Print this page

        

*** 21,58 **** * questions. */ /* * @test ! * @bug 4288198 * @summary Killing a Timer thread causes the Timer to fail silently on * subsequent use. */ import java.util.*; public class KillThread { public static void main (String[] args) throws Exception { - final Thread[] tdThread = new Thread[1]; Timer t = new Timer(); // Start a mean event that kills the timer thread t.schedule(new TimerTask() { public void run() { ! tdThread[0] = Thread.currentThread(); throw new ThreadDeath(); } }, 0); // Wait for mean event to do the deed and thread to die. try { do { Thread.sleep(100); ! } while(tdThread[0] == null); } catch(InterruptedException e) { } ! tdThread[0].join(); // Try to start another event try { // Timer thread is dead now t.schedule(new TimerTask() { --- 21,58 ---- * questions. */ /* * @test ! * @bug 4288198 6818464 * @summary Killing a Timer thread causes the Timer to fail silently on * subsequent use. */ import java.util.*; public class KillThread { + static volatile Thread tdThread; public static void main (String[] args) throws Exception { Timer t = new Timer(); // Start a mean event that kills the timer thread t.schedule(new TimerTask() { public void run() { ! tdThread = Thread.currentThread(); throw new ThreadDeath(); } }, 0); // Wait for mean event to do the deed and thread to die. try { do { Thread.sleep(100); ! } while(tdThread == null); } catch(InterruptedException e) { } ! tdThread.join(); // Try to start another event try { // Timer thread is dead now t.schedule(new TimerTask() {