概述
在javathread的run函数中输出当前线程状态,显示结果是new,这是怎么回事?代码如下:publicclassTest{publicstaticvoidmain(String[]args){ThreadPoolExecutorexecutor=newThreadFac...
在java thread的run函数中输出当前线程状态,显示结果是new,这是怎么回事?
代码如下:
public class Test {
public static void main(String[] args){
ThreadPoolExecutor executor = new ThreadFactory(50, 200, 60,
TimeUnit.SECONDS, new ArrayBlockingQueue(1000),
new ThreadPoolExecutor.CallerRunsPolicy());
for(int i=0;i<15;i++){
Task task = new Task();
executor.execute(task);
}
}
}
public class Task extends Thread{
@Override
public void run(){
System.out.println(this.getId() + " "+ this.getName() + ": " + this.getState());
}
}
输出结果:
13 Thread-2: NEW
21 Thread-6: NEW
15 Thread-3: NEW
11 Thread-1: NEW
17 Thread-4: NEW
19 Thread-5: NEW
9 Thread-0: NEW
27 Thread-9: NEW
23 Thread-7: NEW
25 Thread-8: NEW
29 Thread-10: NEW
31 Thread-11: NEW
33 Thread-12: NEW
35 Thread-13: NEW
37 Thread-14: NEW
展开
最后
以上就是含蓄八宝粥为你收集整理的java new thread run_java thread在run函数中输出status是new的全部内容,希望文章能够帮你解决java new thread run_java thread在run函数中输出status是new所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复