package com.umeox.babywei.k3.service;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
@Component
public class JdbcExecutor implements InitializingBean, DisposableBean {
protected Logger logger = LoggerFactory.getLogger(this.getClass());
public static JdbcExecutor instance;
private ThreadPoolTaskExecutor jdbcExecutor = null;
private volatile boolean stopping = false;
@Override
public void afterPropertiesSet() throws Exception {
instance = this;
int limit = 100;
// 实际扫描线程池
jdbcExecutor = new ThreadPoolTaskExecutor();
jdbcExecutor.setCorePoolSize(limit / 5);
jdbcExecutor.setMaxPoolSize(limit);
jdbcExecutor.setWaitForTasksToCompleteOnShutdown(true);
jdbcExecutor.afterPropertiesSet();
// Thread thread = new Thread(new Runnable() {
// @Override
// public void run() {
// while (!stopping) {
//
// logger.info("JdbcExecutor Status\n. {}",
// jdbcExecutor.getThreadPoolExecutor());
//
// try {
// Thread.sleep(60 * 1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }
// });
//
// thread.start();
}
public void submit(Runnable runnable) {
this.jdbcExecutor.submit(runnable);
}
@Override
public void destroy() throws Exception {
stopping = true;
}
public Future<?> submit(Callable<?> callable) {
return this.jdbcExecutor.submit(callable);
}
}
繁花如伊
冉冉说
慕妹3146593
相关分类