我正在使用spring boot + spring scheduler。我希望在满足某些条件后关闭调度程序。请让我知道如何使它成为可能。
@Component
public class ScheduledTasks {
private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);
static int a=0;
@Autowired ThreadPoolTaskScheduler scheduler;
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Scheduled(fixedRate = 2000)
public void reportCurrentTime() {
if(a==5)
{
//I need code to stop this here
}
log.info("The time is now {}", dateFormat.format(new Date()));
Thread.currentThread().interrupt();
System.out.println(a);
a++;
}
}