Print this page


Split Close
Expand all
Collapse all
          --- old/test/java/util/concurrent/ThreadPoolExecutor/ThrowingTasks.java
          +++ new/test/java/util/concurrent/ThreadPoolExecutor/ThrowingTasks.java
↓ open down ↓ 27 lines elided ↑ open up ↑
  28   28   * @run main/othervm -XX:-UseVMInterruptibleIO ThrowingTasks
  29   29   * @author Martin Buchholz
  30   30   */
  31   31  
  32   32  import java.security.*;
  33   33  import java.util.*;
  34   34  import java.util.concurrent.*;
  35   35  import java.util.concurrent.atomic.*;
  36   36  
  37   37  public class ThrowingTasks {
  38      -    final static Random rnd = new Random();
       38 +    static final Random rnd = new Random();
  39   39  
  40   40      @SuppressWarnings("serial")
  41   41      static class UncaughtExceptions
  42   42          extends ConcurrentHashMap<Class<?>, Integer> {
  43   43  
  44   44          void inc(Class<?> key) {
  45   45              for (;;) {
  46   46                  Integer i = get(key);
  47   47                  if (i == null) {
  48   48                      if (putIfAbsent(key, 1) == null)
↓ open down ↓ 9 lines elided ↑ open up ↑
  58   58      @SuppressWarnings("serial")
  59   59      static class UncaughtExceptionsTable
  60   60          extends Hashtable<Class<?>, Integer> {
  61   61  
  62   62          synchronized void inc(Class<?> key) {
  63   63              Integer i = get(key);
  64   64              put(key, (i == null) ? 1 : i + 1);
  65   65          }
  66   66      }
  67   67  
  68      -    final static UncaughtExceptions uncaughtExceptions
       68 +    static final UncaughtExceptions uncaughtExceptions
  69   69          = new UncaughtExceptions();
  70      -    final static UncaughtExceptionsTable uncaughtExceptionsTable
       70 +    static final UncaughtExceptionsTable uncaughtExceptionsTable
  71   71          = new UncaughtExceptionsTable();
  72      -    final static AtomicLong totalUncaughtExceptions
       72 +    static final AtomicLong totalUncaughtExceptions
  73   73          = new AtomicLong(0);
  74      -    final static CountDownLatch uncaughtExceptionsLatch
       74 +    static final CountDownLatch uncaughtExceptionsLatch
  75   75          = new CountDownLatch(24);
  76   76  
  77      -    final static Thread.UncaughtExceptionHandler handler
       77 +    static final Thread.UncaughtExceptionHandler handler
  78   78          = new Thread.UncaughtExceptionHandler() {
  79   79                  public void uncaughtException(Thread t, Throwable e) {
  80   80                      check(! Thread.currentThread().isInterrupted());
  81   81                      totalUncaughtExceptions.getAndIncrement();
  82   82                      uncaughtExceptions.inc(e.getClass());
  83   83                      uncaughtExceptionsTable.inc(e.getClass());
  84   84                      uncaughtExceptionsLatch.countDown();
  85   85                  }};
  86   86  
  87      -    final static ThreadGroup tg = new ThreadGroup("Flaky");
       87 +    static final ThreadGroup tg = new ThreadGroup("Flaky");
  88   88  
  89      -    final static ThreadFactory tf = new ThreadFactory() {
       89 +    static final ThreadFactory tf = new ThreadFactory() {
  90   90              public Thread newThread(Runnable r) {
  91   91                  Thread t = new Thread(tg, r);
  92   92                  t.setUncaughtExceptionHandler(handler);
  93   93                  return t;
  94   94              }};
  95   95  
  96      -    final static RuntimeException rte = new RuntimeException();
  97      -    final static Error error = new Error();
  98      -    final static Throwable weird = new Throwable();
  99      -    final static Exception checkedException = new Exception();
       96 +    static final RuntimeException rte = new RuntimeException();
       97 +    static final Error error = new Error();
       98 +    static final Throwable weird = new Throwable();
       99 +    static final Exception checkedException = new Exception();
 100  100  
 101  101      static class Thrower implements Runnable {
 102  102          Throwable t;
 103  103          Thrower(Throwable t) { this.t = t; }
 104  104          @SuppressWarnings("deprecation")
 105  105          public void run() { if (t != null) Thread.currentThread().stop(t); }
 106  106      }
 107  107  
 108      -    final static Thrower noThrower      = new Thrower(null);
 109      -    final static Thrower rteThrower     = new Thrower(rte);
 110      -    final static Thrower errorThrower   = new Thrower(error);
 111      -    final static Thrower weirdThrower   = new Thrower(weird);
 112      -    final static Thrower checkedThrower = new Thrower(checkedException);
      108 +    static final Thrower noThrower      = new Thrower(null);
      109 +    static final Thrower rteThrower     = new Thrower(rte);
      110 +    static final Thrower errorThrower   = new Thrower(error);
      111 +    static final Thrower weirdThrower   = new Thrower(weird);
      112 +    static final Thrower checkedThrower = new Thrower(checkedException);
 113  113  
 114      -    final static List<Thrower> throwers = Arrays.asList(
      114 +    static final List<Thrower> throwers = Arrays.asList(
 115  115          noThrower, rteThrower, errorThrower, weirdThrower, checkedThrower);
 116  116  
 117  117      static class Flaky implements Runnable {
 118  118          final Runnable beforeExecute;
 119  119          final Runnable execute;
 120  120          Flaky(Runnable beforeExecute,
 121  121                Runnable execute) {
 122  122              this.beforeExecute = beforeExecute;
 123  123              this.execute = execute;
 124  124          }
↓ open down ↓ 144 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX