< prev index next >

test/jdk/java/util/concurrent/ThreadPoolExecutor/ThreadRestarts.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 and Jason Mehrens with assistance from
  30  * members of JCP JSR-166 Expert Group and released to the public
  31  * domain, as explained at
  32  * http://creativecommons.org/publicdomain/zero/1.0/
  33  */
  34 
  35 /*
  36  * @test
  37  * @summary Only one thread should be created when a thread needs to
  38  * be kept alive to service a delayed task waiting in the queue.
  39  * @library /lib/testlibrary/
  40  */
  41 
  42 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  43 
  44 import java.util.concurrent.ScheduledThreadPoolExecutor;
  45 import java.util.concurrent.ThreadFactory;
  46 import java.util.concurrent.atomic.AtomicLong;
  47 import jdk.testlibrary.Utils;
  48 
  49 public class ThreadRestarts {
  50     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  51     static final long FAR_FUTURE_MS = 10 * LONG_DELAY_MS;
  52 
  53     public static void main(String[] args) throws Exception {
  54         test(false);
  55         test(true);
  56     }
  57 
  58     private static void test(boolean allowTimeout) throws Exception {
  59         CountingThreadFactory ctf = new CountingThreadFactory();
  60         ScheduledThreadPoolExecutor stpe
  61             = new ScheduledThreadPoolExecutor(10, ctf);
  62         try {
  63             // schedule a dummy task in the "far future"
  64             Runnable nop = new Runnable() { public void run() {}};
  65             stpe.schedule(nop, FAR_FUTURE_MS, MILLISECONDS);
  66             stpe.setKeepAliveTime(1L, MILLISECONDS);
  67             stpe.allowCoreThreadTimeOut(allowTimeout);




  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 and Jason Mehrens with assistance from
  30  * members of JCP JSR-166 Expert Group and released to the public
  31  * domain, as explained at
  32  * http://creativecommons.org/publicdomain/zero/1.0/
  33  */
  34 
  35 /*
  36  * @test
  37  * @summary Only one thread should be created when a thread needs to
  38  * be kept alive to service a delayed task waiting in the queue.
  39  * @library /test/lib
  40  */
  41 
  42 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  43 
  44 import java.util.concurrent.ScheduledThreadPoolExecutor;
  45 import java.util.concurrent.ThreadFactory;
  46 import java.util.concurrent.atomic.AtomicLong;
  47 import jdk.test.lib.Utils;
  48 
  49 public class ThreadRestarts {
  50     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  51     static final long FAR_FUTURE_MS = 10 * LONG_DELAY_MS;
  52 
  53     public static void main(String[] args) throws Exception {
  54         test(false);
  55         test(true);
  56     }
  57 
  58     private static void test(boolean allowTimeout) throws Exception {
  59         CountingThreadFactory ctf = new CountingThreadFactory();
  60         ScheduledThreadPoolExecutor stpe
  61             = new ScheduledThreadPoolExecutor(10, ctf);
  62         try {
  63             // schedule a dummy task in the "far future"
  64             Runnable nop = new Runnable() { public void run() {}};
  65             stpe.schedule(nop, FAR_FUTURE_MS, MILLISECONDS);
  66             stpe.setKeepAliveTime(1L, MILLISECONDS);
  67             stpe.allowCoreThreadTimeOut(allowTimeout);


< prev index next >