81,092
社区成员
发帖
与我相关
我的任务
分享
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
RejectedExecutionHandler handler) {
this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
Executors.defaultThreadFactory(), handler);
}
线程池创建的时候,有一个handler就是处理异常的,可以实现那个接口写自己的逻辑,当异常出现时,调用线程池的shutdownNow() 方法就可以了 具体可查api[/quote]
你这个是实现Runnable接口。我的线程需要有返回值实现的是Callable接口啊。 public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
TimeUnit unit,
BlockingQueue<Runnable> workQueue,
RejectedExecutionHandler handler) {
this(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue,
Executors.defaultThreadFactory(), handler);
}
线程池创建的时候,有一个handler就是处理异常的,可以实现那个接口写自己的逻辑,当异常出现时,调用线程池的shutdownNow() 方法就可以了 具体可查api