package org.example.geteclient.task; import lombok.extern.slf4j.Slf4j; import org.example.geteclient.GeteClientApplication; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; /** * @program: demo * @description: * @create: 2024-08-05 10:04 **/ @Component @Slf4j public class RunTask { @Autowired private ConfigurableApplicationContext context; @Scheduled(cron = "0 0 */3 * * ?") public void restart() { Thread restartThread = new Thread(() -> { try { SpringApplication.exit(context, () -> 0); SpringApplication.run(GeteClientApplication.class); log.info("bitgets ws 重启成功"); } catch (Exception e) { e.printStackTrace(); log.error("bitgets ws 重启失败"); } }); restartThread.setDaemon(false); restartThread.start(); log.info("bitgets ws 重启失败"); } }