< prev index next >

test/jdk/java/util/concurrent/FutureTask/CancelledFutureLoops.java

Print this page
rev 51731 : imported patch 8210732


  20  * questions.
  21  */
  22 
  23 /*
  24  * This file is available under and governed by the GNU General Public
  25  * License version 2 only, as published by the Free Software Foundation.
  26  * However, the following notice accompanied the original version of this
  27  * file:
  28  *
  29  * Written by Doug Lea with assistance from members of JCP JSR-166
  30  * Expert Group and released to the public domain, as explained at
  31  * http://creativecommons.org/publicdomain/zero/1.0/
  32  */
  33 
  34 /*
  35  * @test
  36  * @bug 4486658
  37  * @summary Checks for responsiveness of futures to cancellation.
  38  * Runs under the assumption that ITERS computations require more than
  39  * TIMEOUT msecs to complete.
  40  * @library /lib/testlibrary/
  41  * @run main/timeout=2000 CancelledFutureLoops
  42  */
  43 
  44 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  45 
  46 import java.util.SplittableRandom;
  47 import java.util.concurrent.BrokenBarrierException;
  48 import java.util.concurrent.Callable;
  49 import java.util.concurrent.CyclicBarrier;
  50 import java.util.concurrent.ExecutionException;
  51 import java.util.concurrent.ExecutorService;
  52 import java.util.concurrent.Executors;
  53 import java.util.concurrent.Future;
  54 import java.util.concurrent.locks.ReentrantLock;
  55 import jdk.testlibrary.Utils;
  56 
  57 public final class CancelledFutureLoops {
  58     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  59     static final ExecutorService pool = Executors.newCachedThreadPool();
  60     static final SplittableRandom rnd = new SplittableRandom();
  61     static boolean print = false;
  62     static final int ITERS = 1000000;
  63     static final long TIMEOUT = 100;
  64 
  65     public static void main(String[] args) throws Exception {
  66         int maxThreads = 5;
  67         if (args.length > 0)
  68             maxThreads = Integer.parseInt(args[0]);
  69 
  70         print = true;
  71 
  72         for (int i = 2; i <= maxThreads; i += (i+1) >>> 1) {
  73             System.out.print("Threads: " + i);
  74             try {
  75                 new FutureLoop(i, rnd.split()).test();




  20  * questions.
  21  */
  22 
  23 /*
  24  * This file is available under and governed by the GNU General Public
  25  * License version 2 only, as published by the Free Software Foundation.
  26  * However, the following notice accompanied the original version of this
  27  * file:
  28  *
  29  * Written by Doug Lea with assistance from members of JCP JSR-166
  30  * Expert Group and released to the public domain, as explained at
  31  * http://creativecommons.org/publicdomain/zero/1.0/
  32  */
  33 
  34 /*
  35  * @test
  36  * @bug 4486658
  37  * @summary Checks for responsiveness of futures to cancellation.
  38  * Runs under the assumption that ITERS computations require more than
  39  * TIMEOUT msecs to complete.
  40  * @library /test/lib
  41  * @run main/timeout=2000 CancelledFutureLoops
  42  */
  43 
  44 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  45 
  46 import java.util.SplittableRandom;
  47 import java.util.concurrent.BrokenBarrierException;
  48 import java.util.concurrent.Callable;
  49 import java.util.concurrent.CyclicBarrier;
  50 import java.util.concurrent.ExecutionException;
  51 import java.util.concurrent.ExecutorService;
  52 import java.util.concurrent.Executors;
  53 import java.util.concurrent.Future;
  54 import java.util.concurrent.locks.ReentrantLock;
  55 import jdk.test.lib.Utils;
  56 
  57 public final class CancelledFutureLoops {
  58     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  59     static final ExecutorService pool = Executors.newCachedThreadPool();
  60     static final SplittableRandom rnd = new SplittableRandom();
  61     static boolean print = false;
  62     static final int ITERS = 1000000;
  63     static final long TIMEOUT = 100;
  64 
  65     public static void main(String[] args) throws Exception {
  66         int maxThreads = 5;
  67         if (args.length > 0)
  68             maxThreads = Integer.parseInt(args[0]);
  69 
  70         print = true;
  71 
  72         for (int i = 2; i <= maxThreads; i += (i+1) >>> 1) {
  73             System.out.print("Threads: " + i);
  74             try {
  75                 new FutureLoop(i, rnd.split()).test();


< prev index next >