1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/*
25
25
* @test
26
- * @bug 5047639
26
+ * @bug 5047639 8132785
27
27
* @summary Check that the "java-level" APIs provide a consistent view of
28
28
* the thread list
29
+ * @comment Must run in othervm mode to avoid interference from other tests.
30
+ * @run main/othervm ThreadLists
29
31
*/
30
32
import java .lang .management .ManagementFactory ;
31
33
import java .lang .management .ThreadMXBean ;
@@ -50,6 +52,19 @@ public static void main(String args[]) {
50
52
// get the thread count
51
53
int activeCount = top .activeCount ();
52
54
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
+
53
68
Map <Thread , StackTraceElement []> stackTraces = Thread .getAllStackTraces ();
54
69
55
70
ThreadMXBean threadBean = ManagementFactory .getThreadMXBean ();
@@ -68,6 +83,11 @@ public static void main(String args[]) {
68
83
if (activeCount != threadIds .length ) failed = true ;
69
84
70
85
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
+ }
71
91
throw new RuntimeException ("inconsistent results" );
72
92
}
73
93
}
0 commit comments