Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- public class ScheduledTasks {
- @Autowired
- private MyService myService;
- @Scheduled(cron = "0 0 */1 * * ?")
- public void scheduleAsyncTask() {
- myService.doAsync();
- }
- }
- @Service
- public class MyService {
- @Async("threadTaskExecutor")
- public void doAsync() {
- //Do Stuff
- }
- }
- @CrossOrigin
- @RestController
- @RequestMapping("/mysrv")
- public class MyController {
- @Autowired
- private MyService myService;
- @CrossOrigin
- @RequestMapping(value = "/", method = RequestMethod.POST)
- public void postAsyncUpdate() {
- myService.doAsync();
- }
- }
- @Autowired
- private MyDbRepo myDbRepo;
- @Async("threadTaskExecutor")
- public void doAsync() {
- if (!myDbRepo.isRunning()) {
- myDbRepo.setIsRunning(true);
- //Do Stuff
- myDbRepo.setIsRunning(false);
- } else {
- LOG.info("The Async task is already running");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement