Peter Penzov
Peter Penzov

Reputation: 1708

Call Spring Scheduler execution from Java code

I have this simple example of Spring Scheduler:

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class AppScheduler {

    @Scheduled(fixedRate = 10000)
    public void myScheduler() {
        System.out.println("Test print");
    }

}

Is there a way to trigger execution in the current moment let's say from web page?

Upvotes: 0

Views: 84

Answers (1)

Mạnh Quyết Nguyễn
Mạnh Quyết Nguyễn

Reputation: 18235

Just make a dump controller to call myScheduler method:

@Controller
public class DumpController {
     @Autowired
     private AppScheduler scheduler;

     @RequestMapping("/ping")
     public void ping() {
         scheduler.myScheduler();
     }
}

Upvotes: 1

Related Questions