简体   繁体   English

为Java主方法执行创建了多少个线程?

[英]How many threads is created for java main method execution?

I have a java main method. 我有一个Java主方法。 I put the java main thread sleep for sometime. 我把Java主线程休眠了一段时间。

public static void main(String[] args) {
    Thread.sleep(10);
}

Total, how many number of threads would be created for java main execution (including deamon thread) 总计,将为Java主执行创建多少个线程(包括守护线程)

Exactly one. 就是一个

You can check it by adding a line: 您可以通过添加一行来检查它:

System.out.println(Thread.activeCount());

Sleeping a thread creates no new threads: 休眠线程不会创建新线程:

sleep(long millis) Causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. sleep(long millis)使当前正在执行的线程进入休眠状态(暂时停止执行)达指定的毫秒数,这取决于系统计时器和调度程序的精度和准确性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM