五虎上将收服线程池
package threadpool;import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;/*** 描述: 演示關(guān)閉線程池*/
public class ShutDown {public static void main(String[] args) throws InterruptedException {ExecutorService executorService = Executors.newFixedThreadPool(10);for (int i = 0; i < 100; i++) {executorService.execute(new ShutDownTask());}Thread.sleep(1500);
// List<Runnable> runnableList = executorService.shutdownNow();executorService.shutdown();executorService.execute(new ShutDownTask());
// boolean b = executorService.awaitTermination(7L, TimeUnit.SECONDS);
// System.out.println(b);
// System.out.println(executorService.isShutdown());
// executorService.shutdown();
// System.out.println(executorService.isShutdown());
// System.out.println(executorService.isTerminated());
// Thread.sleep(10000);
// System.out.println(executorService.isTerminated());// executorService.execute(new ShutDownTask());}
}class ShutDownTask implements Runnable {@Overridepublic void run() {try {Thread.sleep(500);System.out.println(Thread.currentThread().getName());} catch (InterruptedException e) {System.out.println(Thread.currentThread().getName() + "被中斷了");}}
}
?
總結(jié)
- 上一篇: 对比线程池的特点
- 下一篇: Executor家族的辨析