< prev index next >

test/jdk/java/util/concurrent/locks/ReentrantLock/SimpleReentrantLockLoops.java

Print this page
rev 51731 : imported patch 8210732


  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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 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 multiple threads using a single lock
  38  * @library /lib/testlibrary/
  39  */
  40 
  41 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  42 
  43 import java.util.concurrent.CyclicBarrier;
  44 import java.util.concurrent.ExecutorService;
  45 import java.util.concurrent.Executors;
  46 import java.util.concurrent.locks.ReentrantLock;
  47 import java.util.concurrent.ThreadLocalRandom;
  48 import jdk.testlibrary.Utils;
  49 
  50 public final class SimpleReentrantLockLoops {
  51     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  52     static final ExecutorService pool = Executors.newCachedThreadPool();
  53     static boolean print = false;
  54     static int iters = 100_000;
  55 
  56     public static void main(String[] args) throws Exception {
  57         int maxThreads = 5;
  58         if (args.length > 0)
  59             maxThreads = Integer.parseInt(args[0]);
  60 
  61         print = true;
  62 
  63         int reps = 2;
  64         for (int i = 1; i <= maxThreads; i += (i+1) >>> 1) {
  65             int n = reps;
  66             if (reps > 1) --reps;
  67             while (n-- > 0) {
  68                 System.out.print("Threads: " + i);




  18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  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 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 multiple threads using a single lock
  38  * @library /test/lib
  39  */
  40 
  41 import static java.util.concurrent.TimeUnit.MILLISECONDS;
  42 
  43 import java.util.concurrent.CyclicBarrier;
  44 import java.util.concurrent.ExecutorService;
  45 import java.util.concurrent.Executors;
  46 import java.util.concurrent.locks.ReentrantLock;
  47 import java.util.concurrent.ThreadLocalRandom;
  48 import jdk.test.lib.Utils;
  49 
  50 public final class SimpleReentrantLockLoops {
  51     static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
  52     static final ExecutorService pool = Executors.newCachedThreadPool();
  53     static boolean print = false;
  54     static int iters = 100_000;
  55 
  56     public static void main(String[] args) throws Exception {
  57         int maxThreads = 5;
  58         if (args.length > 0)
  59             maxThreads = Integer.parseInt(args[0]);
  60 
  61         print = true;
  62 
  63         int reps = 2;
  64         for (int i = 1; i <= maxThreads; i += (i+1) >>> 1) {
  65             int n = reps;
  66             if (reps > 1) --reps;
  67             while (n-- > 0) {
  68                 System.out.print("Threads: " + i);


< prev index next >