Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.

Commit c93b24d

Browse files
author
David Holmes
committed
8132785: java/lang/management/ThreadMXBean/ThreadLists.java fails intermittently
Reviewed-by: alanb, kevinw, dcubed, sspitsyn
1 parent 9a1bbaf commit c93b24d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

test/jdk/ProblemList.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ com/sun/management/OperatingSystemMXBean/GetSystemCpuLoad.java 8030957 aix-all
567567
java/lang/management/MemoryMXBean/Pending.java 8158837 generic-all
568568
java/lang/management/MemoryMXBean/PendingAllGC.sh 8158837 generic-all
569569
java/lang/management/ThreadMXBean/ThreadMXBeanStateTest.java 8247426 generic-all
570-
java/lang/management/ThreadMXBean/ThreadLists.java 8132785 generic-all
571570

572571
sun/management/jdp/JdpDefaultsTest.java 8241865 linux-aarch64,macosx-all
573572
sun/management/jdp/JdpJmxRemoteDynamicPortTest.java 8241865 macosx-all

test/jdk/java/lang/management/ThreadMXBean/ThreadLists.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2004, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,9 +23,11 @@
2323

2424
/*
2525
* @test
26-
* @bug 5047639
26+
* @bug 5047639 8132785
2727
* @summary Check that the "java-level" APIs provide a consistent view of
2828
* the thread list
29+
* @comment Must run in othervm mode to avoid interference from other tests.
30+
* @run main/othervm ThreadLists
2931
*/
3032
import java.lang.management.ManagementFactory;
3133
import java.lang.management.ThreadMXBean;
@@ -50,6 +52,19 @@ public static void main(String args[]) {
5052
// get the thread count
5153
int activeCount = top.activeCount();
5254

55+
// Now enumerate to see if we find any extras yet.
56+
// Ensure the array is big enough for a few extras.
57+
Thread[] threads = new Thread[activeCount * 2];
58+
int newCount = top.enumerate(threads);
59+
if (newCount != activeCount) {
60+
System.out.println("Found different threads after enumeration:");
61+
} else {
62+
System.out.println("Initial set of enumerated threads:");
63+
}
64+
for (int i = 0; i < newCount; i++) {
65+
System.out.println(" - Thread: " + threads[i].getName());
66+
}
67+
5368
Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
5469

5570
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
@@ -68,6 +83,11 @@ public static void main(String args[]) {
6883
if (activeCount != threadIds.length) failed = true;
6984

7085
if (failed) {
86+
System.out.println("Set of stack-traced threads:");
87+
for (Thread t : stackTraces.keySet()) {
88+
System.out.println(" - Thread: " +
89+
(t != null ? t.getName() : "null!"));
90+
}
7191
throw new RuntimeException("inconsistent results");
7292
}
7393
}

0 commit comments

Comments
 (0)