如果我扩展ThreadPoolExecutor,有没有办法重用工厂方法,如:
public static ExecutorService newSingleThreadExecutor()
或者我必须调用我的ThreadPoolExecutor子类的构造函数并输入所有参数:
class MyThreadPoolExecutor extends ThreadPoolExecutor {
...
public MyThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
};
...
}
答案 0 :(得分:-1)
没有办法做第一个。我建议做另一种方式:
class MyThreadPoolExecutor extends ThreadPoolExecutor {
...
public MyThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue, RejectedExecutionHandler handler) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, handler);
};
...
}
因为这是唯一的方法。