线程池的创建

引自 https://www.cnblogs.com/ruiati/p/6133168.html

public static ExecutorService newFixedThreadPool(int nThreads) 
创建固定数目线程的线程池。
public static ExecutorService newCachedThreadPool() 
创建一个可缓存的线程池,调用execute 将重用以前构造的线程(如果线程可用)。如果现有线程没有可用的,则创建一个新线程并添加到池中。终止并从缓存中移除那些已有 60 秒钟未被使用的线程。
public static ExecutorService newSingleThreadExecutor() 
创建一个单线程化的Executor。
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize) 
创建一个支持定时及周期性的任务执行的线程池,多数情况下可用来替代Timer类。

线程创建的三种方式:继承Thread、实现Runnable接口、实现Callable接口。
    继承Thread,但Thread本质上也是实现了Runnable接口,
    实现Runnable接口,没有返回值
    实现Callable接口是JDK1.5新引入的特征,主要实现了有返回结果

猜你喜欢

转载自www.cnblogs.com/syd-fish-cat/p/9281529.html