test/java/util/concurrent/ThreadPoolExecutor/ShutdownNowExecuteRace.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  64             check(pool.awaitTermination(3L, TimeUnit.MINUTES));
  65         }
  66         quit = true;
  67         thread.join();
  68     }
  69 
  70     //--------------------- Infrastructure ---------------------------
  71     static volatile int passed = 0, failed = 0;
  72     static void pass() {passed++;}
  73     static void fail() {failed++; Thread.dumpStack();}
  74     static void fail(String msg) {System.out.println(msg); fail();}
  75     static void unexpected(Throwable t) {failed++; t.printStackTrace();}
  76     static void check(boolean cond) {if (cond) pass(); else fail();}
  77     static void equal(Object x, Object y) {
  78         if (x == null ? y == null : x.equals(y)) pass();
  79         else fail(x + " not equal to " + y);}
  80     public static void main(String[] args) throws Throwable {
  81         try {realMain(args);} catch (Throwable t) {unexpected(t);}
  82         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
  83         if (failed > 0) throw new AssertionError("Some tests failed");}
  84     private abstract static class Fun {abstract void f() throws Throwable;}
  85     static void THROWS(Class<? extends Throwable> k, Fun... fs) {
  86         for (Fun f : fs)
  87             try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
  88             catch (Throwable t) {
  89                 if (k.isAssignableFrom(t.getClass())) pass();
  90                 else unexpected(t);}}
  91     private abstract static class CheckedThread extends Thread {
  92         abstract void realRun() throws Throwable;
  93         public void run() {
  94             try {realRun();} catch (Throwable t) {unexpected(t);}}}
  95 }
   1 /*
   2  * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


  64             check(pool.awaitTermination(3L, TimeUnit.MINUTES));
  65         }
  66         quit = true;
  67         thread.join();
  68     }
  69 
  70     //--------------------- Infrastructure ---------------------------
  71     static volatile int passed = 0, failed = 0;
  72     static void pass() {passed++;}
  73     static void fail() {failed++; Thread.dumpStack();}
  74     static void fail(String msg) {System.out.println(msg); fail();}
  75     static void unexpected(Throwable t) {failed++; t.printStackTrace();}
  76     static void check(boolean cond) {if (cond) pass(); else fail();}
  77     static void equal(Object x, Object y) {
  78         if (x == null ? y == null : x.equals(y)) pass();
  79         else fail(x + " not equal to " + y);}
  80     public static void main(String[] args) throws Throwable {
  81         try {realMain(args);} catch (Throwable t) {unexpected(t);}
  82         System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
  83         if (failed > 0) throw new AssertionError("Some tests failed");}







  84     private abstract static class CheckedThread extends Thread {
  85         abstract void realRun() throws Throwable;
  86         public void run() {
  87             try {realRun();} catch (Throwable t) {unexpected(t);}}}
  88 }