在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
展开