< prev index next >

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

Print this page
rev 51731 : imported patch 8210732


  19  * or visit www.oracle.com if you need additional information or have any
  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 Martin Buchholz with assistance from members of JCP
  30  * JSR-166 Expert Group and released to the public domain, as
  31  * explained at http://creativecommons.org/publicdomain/zero/1.0/
  32  */
  33 
  34 /*
  35  * @test
  36  * @bug 8073704
  37  * @summary Checks that once isDone() returns true,
  38  * get() never throws InterruptedException or TimeoutException
  39  * @library /lib/testlibrary/
  40  */
  41 
  42 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  43 
  44 import java.util.ArrayList;
  45 import java.util.concurrent.Callable;
  46 import java.util.concurrent.CountDownLatch;
  47 import java.util.concurrent.ExecutorService;
  48 import java.util.concurrent.Executors;
  49 import java.util.concurrent.Future;
  50 import java.util.concurrent.FutureTask;
  51 import java.util.concurrent.ThreadLocalRandom;
  52 import java.util.concurrent.TimeUnit;
  53 import java.util.concurrent.atomic.AtomicBoolean;
  54 import java.util.concurrent.atomic.AtomicReference;
  55 import jdk.testlibrary.Utils;
  56 
  57 public class DoneMeansDone {
  58     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  59 
  60     public static void main(String[] args) throws Throwable {
  61         final int iters = 1000;
  62         final int nThreads = 2;
  63         final AtomicBoolean done = new AtomicBoolean(false);
  64         final AtomicReference<FutureTask<Boolean>> a = new AtomicReference<>();
  65         final CountDownLatch threadsStarted = new CountDownLatch(nThreads);
  66         final Callable<Boolean> alwaysTrue = new Callable<>() {
  67             public Boolean call() {
  68                 return true;
  69             }};
  70 
  71         final Runnable observer = new Runnable() { public void run() {
  72             threadsStarted.countDown();
  73             final ThreadLocalRandom rnd = ThreadLocalRandom.current();
  74             try {
  75                 for (FutureTask<Boolean> f; !done.get();) {




  19  * or visit www.oracle.com if you need additional information or have any
  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 Martin Buchholz with assistance from members of JCP
  30  * JSR-166 Expert Group and released to the public domain, as
  31  * explained at http://creativecommons.org/publicdomain/zero/1.0/
  32  */
  33 
  34 /*
  35  * @test
  36  * @bug 8073704
  37  * @summary Checks that once isDone() returns true,
  38  * get() never throws InterruptedException or TimeoutException
  39  * @library /test/lib
  40  */
  41 
  42 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  43 
  44 import java.util.ArrayList;
  45 import java.util.concurrent.Callable;
  46 import java.util.concurrent.CountDownLatch;
  47 import java.util.concurrent.ExecutorService;
  48 import java.util.concurrent.Executors;
  49 import java.util.concurrent.Future;
  50 import java.util.concurrent.FutureTask;
  51 import java.util.concurrent.ThreadLocalRandom;
  52 import java.util.concurrent.TimeUnit;
  53 import java.util.concurrent.atomic.AtomicBoolean;
  54 import java.util.concurrent.atomic.AtomicReference;
  55 import jdk.test.lib.Utils;
  56 
  57 public class DoneMeansDone {
  58     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  59 
  60     public static void main(String[] args) throws Throwable {
  61         final int iters = 1000;
  62         final int nThreads = 2;
  63         final AtomicBoolean done = new AtomicBoolean(false);
  64         final AtomicReference<FutureTask<Boolean>> a = new AtomicReference<>();
  65         final CountDownLatch threadsStarted = new CountDownLatch(nThreads);
  66         final Callable<Boolean> alwaysTrue = new Callable<>() {
  67             public Boolean call() {
  68                 return true;
  69             }};
  70 
  71         final Runnable observer = new Runnable() { public void run() {
  72             threadsStarted.countDown();
  73             final ThreadLocalRandom rnd = ThreadLocalRandom.current();
  74             try {
  75                 for (FutureTask<Boolean> f; !done.get();) {


< prev index next >