public class SchedulerService extends Service {
private static final int DEFAULT_POOL_SIZE = 2 * Runtime.getRuntime().availableProcessors();
private int poolSize;
private ScheduledExecutorService pool;
public int getPoolSize() {
return poolSize;
}
public void setPoolSize(int poolSize) {
if (poolSize < 0) {
logger.warning("pool size error,use default value:" + DEFAULT_POOL_SIZE);
poolSize = DEFAULT_POOL_SIZE;
}
this.poolSize = poolSize;
}
protected void initService() throws ServiceException {
pool = Executors.newScheduledThreadPool(poolSize);
}
protected void startService() throws ServiceException {
//
}
protected void stopService() throws ServiceException {
pool.shutdown();
try {
if (!pool.awaitTermination(60, TimeUnit.SECONDS)) {
pool.shutdownNow();
if (!pool.awaitTermination(60, TimeUnit.SECONDS)) {
logger.severe("Pool did not terminate");
}
}
} cat
调度封装
最新推荐文章于 2022-10-18 11:03:32 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)