标签:current 影响 handler 系统 hand 频繁 时间 actor factory
java中为了提高并发度,可以使用多线程共同执行,但是如果有大量线程短时间之内被创建和销毁,会占用大量的系统时间,影响系统效率。为了解决这个问题,java中引入了线程池,可以使创建好的线程在指定的时间内由系统统一管理,而不是在执行时创建,执行后就销毁,从而避免了频繁创建、销毁线程带来的系统开销。
在Java中,线程池的概念是Executor这个接口,具体实现为ThreadPoolExecutor类,java.uitl.concurrent.ThreadPoolExecutor是线程池中最核心的一个类,ThreadPoolExecutor继承了AbstractExecutorService类,并提供了四个构造器:
public class ThreadPoolExecutor extends AbstractExecutorService { ..... public ThreadPoolExecutor( int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue ); public ThreadPoolExecutor( int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory ); public ThreadPoolExecutor( int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler ); public ThreadPoolExecutor( int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, ThreadFactory threadFactory, RejectedExecutionHandler handler ); ... }
二、线程池的使用(ThreadPoolExecutor)
三、
标签:current 影响 handler 系统 hand 频繁 时间 actor factory
原文地址:https://www.cnblogs.com/myitnews/p/12038404.html