提问,为社么是4不是3啊?关于简单的THREAD

jeanman 2003-04-09 03:04:32
package threads;

public class PrintStatic implements Runnable{
public static void main(String[] args){
Thread t1=new Thread(new PrintStatic(),"First Thread");
t1.start();
Thread t2=new Thread(new PrintStatic(),"Second Thread");
t2.start();
int numThreads=Thread.activeCount();
System.out.println("The number of threads is: "+numThreads);
Thread[] threads=new Thread[numThreads];
Thread.enumerate(threads);
for(int i=0;i<3;i++)
System.out.println(" Thread named: "+threads[i].getName());
}
public void run(){
try{
Thread.sleep(1000);
}catch(InterruptedException e){
System.out.print("Oh no !I was interrupted");
}
System.out.print("dd");
}
}



System.out.println("The number of threads is: "+numThreads);
书上是3,WHY我的机器上是4
...全文
58 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeanman 2003-04-10
  • 打赏
  • 举报
回复
看看是不是你测试的时候留下的线程
如何看啊?
moumouren 2003-04-09
  • 打赏
  • 举报
回复
应该是3,你看看是不是你测试的时候留下的线程

81,115

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧