< prev index next >

test/jdk/java/util/concurrent/ThreadPoolExecutor/Custom.java

Print this page
rev 51731 : imported patch 8210732


   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  */
  23 
  24 /*
  25  * @test
  26  * @bug 6277663
  27  * @summary Test TPE extensibility framework
  28  * @library /lib/testlibrary/
  29  * @author Martin Buchholz
  30  */
  31 
  32 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  33 
  34 import java.util.concurrent.ArrayBlockingQueue;
  35 import java.util.concurrent.Callable;
  36 import java.util.concurrent.FutureTask;
  37 import java.util.concurrent.RunnableFuture;
  38 import java.util.concurrent.RunnableScheduledFuture;
  39 import java.util.concurrent.ScheduledThreadPoolExecutor;
  40 import java.util.concurrent.ThreadPoolExecutor;
  41 import java.util.concurrent.TimeUnit;
  42 import java.util.concurrent.atomic.AtomicInteger;
  43 import java.util.function.BooleanSupplier;
  44 import jdk.testlibrary.Utils;
  45 
  46 public class Custom {
  47     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  48     static volatile int passed = 0, failed = 0;
  49     static void pass() { passed++; }
  50     static void fail() { failed++; Thread.dumpStack(); }
  51     static void unexpected(Throwable t) { failed++; t.printStackTrace(); }
  52     static void check(boolean cond) { if (cond) pass(); else fail(); }
  53     static void equal(Object x, Object y) {
  54         if (x == null ? y == null : x.equals(y)) pass();
  55         else {System.out.println(x + " not equal to " + y); fail(); }}
  56 
  57     private static class CustomTask<V> extends FutureTask<V> {
  58         public static final AtomicInteger births = new AtomicInteger(0);
  59         CustomTask(Callable<V> c) { super(c); births.getAndIncrement(); }
  60         CustomTask(Runnable r, V v) { super(r, v); births.getAndIncrement(); }
  61     }
  62 
  63     private static class CustomTPE extends ThreadPoolExecutor {
  64         CustomTPE() {




   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  */
  23 
  24 /*
  25  * @test
  26  * @bug 6277663
  27  * @summary Test TPE extensibility framework
  28  * @library /test/lib
  29  * @author Martin Buchholz
  30  */
  31 
  32 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  33 
  34 import java.util.concurrent.ArrayBlockingQueue;
  35 import java.util.concurrent.Callable;
  36 import java.util.concurrent.FutureTask;
  37 import java.util.concurrent.RunnableFuture;
  38 import java.util.concurrent.RunnableScheduledFuture;
  39 import java.util.concurrent.ScheduledThreadPoolExecutor;
  40 import java.util.concurrent.ThreadPoolExecutor;
  41 import java.util.concurrent.TimeUnit;
  42 import java.util.concurrent.atomic.AtomicInteger;
  43 import java.util.function.BooleanSupplier;
  44 import jdk.test.lib.Utils;
  45 
  46 public class Custom {
  47     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  48     static volatile int passed = 0, failed = 0;
  49     static void pass() { passed++; }
  50     static void fail() { failed++; Thread.dumpStack(); }
  51     static void unexpected(Throwable t) { failed++; t.printStackTrace(); }
  52     static void check(boolean cond) { if (cond) pass(); else fail(); }
  53     static void equal(Object x, Object y) {
  54         if (x == null ? y == null : x.equals(y)) pass();
  55         else {System.out.println(x + " not equal to " + y); fail(); }}
  56 
  57     private static class CustomTask<V> extends FutureTask<V> {
  58         public static final AtomicInteger births = new AtomicInteger(0);
  59         CustomTask(Callable<V> c) { super(c); births.getAndIncrement(); }
  60         CustomTask(Runnable r, V v) { super(r, v); births.getAndIncrement(); }
  61     }
  62 
  63     private static class CustomTPE extends ThreadPoolExecutor {
  64         CustomTPE() {


< prev index next >