package org.example.mexcclient.task;
|
|
import lombok.extern.slf4j.Slf4j;
|
import org.example.mexcclient.MexcClientApplication;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.boot.SpringApplication;
|
import org.springframework.context.ConfigurableApplicationContext;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* @program: demo
|
* @description:
|
* @create: 2024-08-05 10:04
|
**/
|
@Component
|
@Slf4j
|
public class RunTask {
|
|
@Autowired
|
private ConfigurableApplicationContext context;
|
|
@Autowired
|
@Qualifier("threadPoolTaskExecutor")
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
// @Scheduled(cron = "0 0/11 * * * ?")
|
public void restart() {
|
// 停止当前线程池中的任务
|
threadPoolTaskExecutor.shutdown();
|
// 创建新的线程池
|
threadPoolTaskExecutor.initialize();
|
Thread restartThread = new Thread(() -> {
|
try {
|
SpringApplication.exit(context, () -> 0);
|
SpringApplication.run(MexcClientApplication.class);
|
log.info("bitgets ws 重启成功");
|
} catch (Exception e) {
|
e.printStackTrace();
|
log.error("bitgets ws 重启失败");
|
}
|
});
|
restartThread.setDaemon(false);
|
restartThread.start();
|
log.info("bitgets ws 重启失败");
|
}
|
|
}
|