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 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 8022642 8065320 8129861
37 * @summary Ensure relative sanity when zero core threads
38 * @library /lib/testlibrary/
39 * @modules java.base/java.util.concurrent:open
40 */
41
42 import static java.util.concurrent.TimeUnit.HOURS;
43 import static java.util.concurrent.TimeUnit.MILLISECONDS;
44
45 import java.lang.reflect.Field;
46 import java.util.concurrent.BlockingQueue;
47 import java.util.concurrent.ScheduledThreadPoolExecutor;
48 import java.util.concurrent.locks.Condition;
49 import java.util.concurrent.locks.ReentrantLock;
50 import java.util.function.BooleanSupplier;
51 import jdk.testlibrary.Utils;
52
53 public class ZeroCoreThreads {
54 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
55
56 static long millisElapsedSince(long startTime) {
57 return (System.nanoTime() - startTime) / (1000L * 1000L);
58 }
59
60 static void spinWaitUntil(BooleanSupplier predicate, long timeoutMillis) {
61 long startTime = -1L;
62 while (!predicate.getAsBoolean()) {
63 if (startTime == -1L)
64 startTime = System.nanoTime();
65 else if (millisElapsedSince(startTime) > timeoutMillis)
66 throw new AssertionError(
67 String.format("timed out after %s ms", timeoutMillis));
68 Thread.yield();
69 }
70 }
71
|
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 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 8022642 8065320 8129861
37 * @summary Ensure relative sanity when zero core threads
38 * @library /test/lib
39 * @modules java.base/java.util.concurrent:open
40 */
41
42 import static java.util.concurrent.TimeUnit.HOURS;
43 import static java.util.concurrent.TimeUnit.MILLISECONDS;
44
45 import java.lang.reflect.Field;
46 import java.util.concurrent.BlockingQueue;
47 import java.util.concurrent.ScheduledThreadPoolExecutor;
48 import java.util.concurrent.locks.Condition;
49 import java.util.concurrent.locks.ReentrantLock;
50 import java.util.function.BooleanSupplier;
51 import jdk.test.lib.Utils;
52
53 public class ZeroCoreThreads {
54 static final long LONG_DELAY_MS = Utils.adjustTimeout(10_000);
55
56 static long millisElapsedSince(long startTime) {
57 return (System.nanoTime() - startTime) / (1000L * 1000L);
58 }
59
60 static void spinWaitUntil(BooleanSupplier predicate, long timeoutMillis) {
61 long startTime = -1L;
62 while (!predicate.getAsBoolean()) {
63 if (startTime == -1L)
64 startTime = System.nanoTime();
65 else if (millisElapsedSince(startTime) > timeoutMillis)
66 throw new AssertionError(
67 String.format("timed out after %s ms", timeoutMillis));
68 Thread.yield();
69 }
70 }
71
|