You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2 KiB

3 years ago
package com.bx.imclient.task;
2 years ago
import com.bx.imcommon.util.ThreadPoolExecutorFactory;
3 years ago
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
3 years ago
import javax.annotation.PreDestroy;
import java.util.concurrent.ExecutorService;
3 years ago
@Slf4j
public abstract class AbstractMessageResultTask implements CommandLineRunner {
3 years ago
2 years ago
private static final ExecutorService EXECUTOR_SERVICE = ThreadPoolExecutorFactory.getThreadPoolExecutor();
@Override
2 years ago
public void run(String... args) {
3 years ago
// 初始化定时器
2 years ago
EXECUTOR_SERVICE.execute(new Runnable() {
@SneakyThrows
@Override
public void run() {
try{
pullMessage();
}catch (Exception e){
log.error("任务调度异常",e);
Thread.sleep(200);
}
if(!EXECUTOR_SERVICE.isShutdown()){
EXECUTOR_SERVICE.execute(this);
3 years ago
}
2 years ago
}
});
3 years ago
}
3 years ago
@PreDestroy
public void destroy(){
log.info("{}线程任务关闭",this.getClass().getSimpleName());
2 years ago
EXECUTOR_SERVICE.shutdown();
3 years ago
}
public abstract void pullMessage();
}