這可能不會回答這個問題,但至少有助於理解發生了什麼。要獲得線程的準確示例,請在您的應用程序中獲取列表表單。 (而不是從調試工具。)
JVM W/O儀器
- 主題:主要
- 主題:指向處理器
- 主題:信號調度
- 主題:附上聽衆
- 主題:終結者
JVM瓦特/儀器(JConsole的)
- 螺紋:主
- 螺紋:JMX服務器連接超時12
- 螺紋:RMI TCP連接(1)-10.1.100.40
- 主題:RMI TCP連接(2)-10.1.100。40
- 螺紋:終結
- 螺紋:參考處理程序
- 螺紋:RMI調度器(0)
- 線程:信號分派器
- 螺紋:RMI TCP接受-0
- 線程:附加監聽
實驗
- 執行下面的代碼
- 啓動JConsole的,並連接到JVM
public class JVM {
public static void main(String... args) throws InterruptedException {
for (java.util.Enumeration<?> e = System.getProperties().propertyNames(); e.hasMoreElements();) {
String prp = (String) e.nextElement();
if (prp.startsWith("java.vm") || prp.startsWith("os.")) {
System.out.format("[%s]=%s%n", prp, System.getProperty(prp));
}
}
java.text.DateFormat df = new java.text.SimpleDateFormat("HH:mm:ss.SSS");
for(;;) {
System.out.format("%s Sampling current threads...%n", df.format(new java.util.Date()));
java.util.Map<Thread, StackTraceElement[]> stacks = Thread.getAllStackTraces();
System.out.format("> Thread Count: %d%n", stacks.size());
for (java.util.Map.Entry<Thread, StackTraceElement[]> entry : stacks.entrySet()) {
Thread thread = entry.getKey();
StackTraceElement[] stack = entry.getValue();
System.out.format("> Thread: %s%n", thread.getName());
// Throwable t = new Throwable("Thread: " + thread.getName());
// t.setStackTrace(stack);
// t.printStackTrace(System.out);
}
java.util.concurrent.TimeUnit.SECONDS.sleep(10);
}
}
}
輸出
[java.vm.version]=16.2-b04
[java.vm.vendor]=Sun Microsystems Inc.
[java.vm.name]=Java HotSpot(TM) Client VM
[java.vm.specification.name]=Java Virtual Machine Specification
[os.arch]=x86
[java.vm.specification.vendor]=Sun Microsystems Inc.
[os.name]=Windows XP
[os.version]=5.1
[java.vm.specification.version]=1.0
[java.vm.info]=mixed mode, sharing
14:03:49.199 Sampling current threads...
> Thread Count: 5
> Thread: main
> Thread: Reference Handler
> Thread: Signal Dispatcher
> Thread: Attach Listener
> Thread: Finalizer
14:03:59.200 Sampling current threads...
> Thread Count: 10
> Thread: main
> Thread: JMX server connection timeout 12
> Thread: RMI TCP Connection(1)-10.1.100.40
> Thread: RMI TCP Connection(2)-10.1.100.40
> Thread: Finalizer
> Thread: Reference Handler
> Thread: RMI Scheduler(0)
> Thread: Signal Dispatcher
> Thread: RMI TCP Accept-0
> Thread: Attach Listener
來源
2011-10-08 19:12:00
TJR
你是如何運行你的代碼?如果您是從IDE內運行它的,那麼您的IDE本身是否可以用Java編寫(並運行)? – DevSolar
我很好奇 - 你如何確定它運行14個線程? – Coffee
是什麼讓你覺得有14個線程? –