简体   繁体   English

从Java代码调用Spring Scheduler执行

[英]Call Spring Scheduler execution from Java code

I have this simple example of Spring Scheduler: 我有一个简单的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? 从网页上说,当前是否有触发执行的方法?

Just make a dump controller to call myScheduler method: 只需使转储控制器调用myScheduler方法即可:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM