7114125: TEST_BUG: java/util/Timer/KillThread.java should use volatile cross thread variable declaration
authoralanb
Mon, 21 Nov 2011 12:57:36 +0000
changeset 11031 33715031b071
parent 11030 4c787684c8eb
child 11032 235588f77727
child 11035 db484258f7ee
7114125: TEST_BUG: java/util/Timer/KillThread.java should use volatile cross thread variable declaration Reviewed-by: dholmes, alanb Contributed-by: gary.adams@oracle.com
jdk/test/java/util/Timer/KillThread.java
--- a/jdk/test/java/util/Timer/KillThread.java	Mon Nov 21 12:51:30 2011 +0000
+++ b/jdk/test/java/util/Timer/KillThread.java	Mon Nov 21 12:57:36 2011 +0000
@@ -31,14 +31,14 @@
 import java.util.*;
 
 public class KillThread {
+    static volatile Thread tdThread;
     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();
+                tdThread = Thread.currentThread();
                 throw new ThreadDeath();
             }
         }, 0);
@@ -47,10 +47,10 @@
         try {
             do {
                 Thread.sleep(100);
-            } while(tdThread[0] == null);
+            } while(tdThread == null);
         } catch(InterruptedException e) {
         }
-        tdThread[0].join();
+        tdThread.join();
 
         // Try to start another event
         try {