固定数量线程池(newFixedThreadPool)允许我们创建固定线程数量的线程池,如果任务数大于线程池中线程的数量,那么任务将等待,如下代码: [size=1em][backcolor=rgb(248, 248, 248) !important]查看源码[size=1em]
打印?
[size=1em][size=1em]
| <span style="font-size:12px;"> ExecutorService threadPool = Executors.newFixedThreadPool(3); |
[size=1em]
| for(int i=1; i<=10; i++){ |
[size=1em]
[size=1em]
| threadPool.execute(new Runnable(){ |
[size=1em]
[size=1em]
[size=1em]
| for(int i=1; i<=10; i++){ |
[size=1em]
| System.out.println(Thread.currentThread().getName() + " is looping of " + i + " the task is " + taskId); |
[size=1em]
[size=1em]
[size=1em]
| } catch (InterruptedException e) { |
[size=1em]
| // TODO Auto-generated catch block |
[size=1em]
[size=1em]
[size=1em]
[size=1em]
[size=1em]
[size=1em]
[size=1em]
[size=1em]
[size=1em]
| System.out.println("add all of 10 task"); |
[size=1em]
这个线程池里面是怎么在创建线程,线程执行完了之后会销毁吗?希望越详细越好
|