test/java/util/concurrent/ThreadPoolExecutor/ThrowingTasks.java

Print this page

        

@@ -23,20 +23,32 @@
 
 /*
  * @test
  * @bug 6450200 6450205 6450207 6450211
  * @summary Test proper handling of tasks that terminate abruptly
- * @run main/othervm -XX:-UseVMInterruptibleIO ThrowingTasks
  * @author Martin Buchholz
  */
 
 import java.security.*;
 import java.util.*;
 import java.util.concurrent.*;
 import java.util.concurrent.atomic.*;
+import java.lang.reflect.Field;
+import sun.misc.Unsafe;
 
 public class ThrowingTasks {
+    static final Unsafe UNSAFE;
+    static {
+        try {
+            Field f = Unsafe.class.getDeclaredField("theUnsafe");
+            f.setAccessible(true);
+            UNSAFE = (Unsafe)f.get(null);
+        } catch (NoSuchFieldException | IllegalAccessException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
     static final Random rnd = new Random();
 
     @SuppressWarnings("serial")
     static class UncaughtExceptions
         extends ConcurrentHashMap<Class<?>, Integer> {

@@ -100,11 +112,11 @@
 
     static class Thrower implements Runnable {
         Throwable t;
         Thrower(Throwable t) { this.t = t; }
         @SuppressWarnings("deprecation")
-        public void run() { if (t != null) Thread.currentThread().stop(t); }
+        public void run() { if (t != null) UNSAFE.throwException(t); }
     }
 
     static final Thrower noThrower      = new Thrower(null);
     static final Thrower rteThrower     = new Thrower(rte);
     static final Thrower errorThrower   = new Thrower(error);