test/java/util/concurrent/locks/ReentrantLock/CancelledLockLoops.java

Print this page

        

@@ -1,5 +1,6 @@
+
 /*
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as

@@ -47,18 +48,15 @@
 import java.util.*;
 
 public final class CancelledLockLoops {
     static final Random rng = new Random();
     static boolean print = false;
-    static final int ITERS = 1000000;
+    static final int ITERS = 5000000;
     static final long TIMEOUT = 100;
 
     public static void main(String[] args) throws Exception {
-        int maxThreads = 5;
-        if (args.length > 0)
-            maxThreads = Integer.parseInt(args[0]);
-
+        int maxThreads = (args.length > 0) ? Integer.parseInt(args[0]) : 5;
         print = true;
 
         for (int i = 2; i <= maxThreads; i += (i+1) >>> 1) {
             System.out.print("Threads: " + i);
             try {

@@ -88,11 +86,11 @@
             Thread[] threads = new Thread[nthreads];
             for (int i = 0; i < threads.length; ++i)
                 threads[i] = new Thread(this);
             for (int i = 0; i < threads.length; ++i)
                 threads[i].start();
-            Thread[] cancels = (Thread[]) (threads.clone());
+            Thread[] cancels = threads.clone();
             Collections.shuffle(Arrays.asList(cancels), rng);
             barrier.await();
             Thread.sleep(TIMEOUT);
             for (int i = 0; i < cancels.length-2; ++i) {
                 cancels[i].interrupt();