68 t.resume();
69 System.out.println("Calling getStackTrace ...");
70 StackTraceElement[] stack = t.getStackTrace();
71 System.out.println(java.util.Arrays.toString(stack));
72 if (stack.length != 0)
73 throw new Error("Terminated thread should have empty java stack trace");
74 System.out.println("Calling setName(\"NewName\") ...");
75 t.setName("NewName");
76 System.out.println("Calling interrupt ...");
77 t.interrupt();
78 System.out.println("Calling stop ...");
79 t.stop();
80
81 // Now the ThreadMXBean functions
82
83 if (mbean.isThreadCpuTimeSupported() &&
84 mbean.isThreadCpuTimeEnabled() ) {
85 System.out.println("Calling getThreadCpuTime ...");
86 long t1 = mbean.getThreadCpuTime(t.getId());
87 if (t1 != -1) {
88 throw new RuntimeException("Invalid ThreadCpuTime returned = " +
89 t1 + " expected = -1");
90 }
91 System.out.println("Okay: getThreadCpuTime() reported -1 as expected");
92 } else {
93 System.out.println("Skipping Thread CPU time test as it's not supported");
94 }
95
96 System.out.println("Calling getThreadUserTime ...");
97 long t1 = mbean.getThreadUserTime(t.getId());
98 if (t1 != -1) {
99 throw new RuntimeException("Invalid ThreadUserTime returned = " +
100 t1 + " expected = -1");
101 }
102 System.out.println("Okay: getThreadUserTime() reported -1 as expected");
103
104 System.out.println("Calling getThreadInfo ...");
105 ThreadInfo info = mbean.getThreadInfo(t.getId());
106 System.out.println(info);
107
108 System.out.println("Calling getThreadInfo with stack ...");
109 info = mbean.getThreadInfo(t.getId(), Integer.MAX_VALUE);
110 System.out.println(info);
111 }
112 }
|
68 t.resume();
69 System.out.println("Calling getStackTrace ...");
70 StackTraceElement[] stack = t.getStackTrace();
71 System.out.println(java.util.Arrays.toString(stack));
72 if (stack.length != 0)
73 throw new Error("Terminated thread should have empty java stack trace");
74 System.out.println("Calling setName(\"NewName\") ...");
75 t.setName("NewName");
76 System.out.println("Calling interrupt ...");
77 t.interrupt();
78 System.out.println("Calling stop ...");
79 t.stop();
80
81 // Now the ThreadMXBean functions
82
83 if (mbean.isThreadCpuTimeSupported() &&
84 mbean.isThreadCpuTimeEnabled() ) {
85 System.out.println("Calling getThreadCpuTime ...");
86 long t1 = mbean.getThreadCpuTime(t.getId());
87 if (t1 != -1) {
88 // At least on PPC, we know threads can still be around a short
89 // instant. In some stress scenarios we seem to grab times of
90 // new threads started with the same thread id. In these cases
91 // we get here.
92 System.out.println("Unexpected: thread still reports CPU time: " + t1);
93 } else {
94 System.out.println("Okay: getThreadCpuTime() reported -1 as expected");
95 }
96 } else {
97 System.out.println("Skipping Thread CPU time test as it's not supported");
98 }
99
100 System.out.println("Calling getThreadUserTime ...");
101 long t1 = mbean.getThreadUserTime(t.getId());
102 if (t1 != -1) {
103 // At least on PPC, we know threads can still be around a short
104 // instant. In some stress scenarios we seem to grab times of
105 // new threads started with the same thread id. In these cases
106 // we get here.
107 System.out.println("Unexpected: thread still reports User time: " + t1);
108 } else {
109 System.out.println("Okay: getThreadUserTime() reported -1 as expected");
110 }
111
112 System.out.println("Calling getThreadInfo ...");
113 ThreadInfo info = mbean.getThreadInfo(t.getId());
114 System.out.println(info);
115
116 System.out.println("Calling getThreadInfo with stack ...");
117 info = mbean.getThreadInfo(t.getId(), Integer.MAX_VALUE);
118 System.out.println(info);
119 }
120 }
|