For simple scheduled tasks, there's no CLI control out of the box in spring/spring-boot.
You will need to implement it yourself.
Below is a simple example of how you can control your scheduled tasks and expose the start/stop methods to the command line using spring shell.
Let's consider you have a common interface for all scheduled tasks:
public interface WithCliControl {
void start();
void stop();
}
So a simple scheduled task will look like:
@Component
public class MyScheduledTask implements WithCliControl {
private AtomicBoolean enabled = new AtomicBoolean(true);
@Scheduled(fixedRate = 5000L)
public void doJob() {
if (enabled.get()) {
System.out.println("job is enabled");
//do your thing
}
}
@Override
public void start() {
enabled.set(true);
}
@Override
public void stop() {
enabled.set(false);
}
}
and the corresponding CLI component will look like:
@ShellComponent
public class MyScheduledTaskCommands {
private final MyScheduledTask myScheduledTask;
public MyScheduledTaskCommands(final MyScheduledTask myScheduledTask) {
this.myScheduledTask = myScheduledTask;
}
@ShellMethod("start task")
public void start() {
myScheduledTask.start();
}
@ShellMethod("stop task")
public void stop() {
myScheduledTask.stop();
}
}
@ShellComponent
and @ShellMethod
are exposing the methods to the Spring Shell process.