I am using spring boot + spring scheduler. I want to shut down the scheduler after some condition is met. Please let me know how to make it possible.
@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++;
}
}