Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. @Component
  2. public class ScheduledTasks {
  3. @Autowired
  4. private MyService myService;
  5.  
  6. @Scheduled(cron = "0 0 */1 * * ?")
  7. public void scheduleAsyncTask() {
  8. myService.doAsync();
  9. }
  10. }
  11.  
  12. @Service
  13. public class MyService {
  14. @Async("threadTaskExecutor")
  15. public void doAsync() {
  16. //Do Stuff
  17. }
  18. }
  19.  
  20. @CrossOrigin
  21. @RestController
  22. @RequestMapping("/mysrv")
  23. public class MyController {
  24. @Autowired
  25. private MyService myService;
  26.  
  27. @CrossOrigin
  28. @RequestMapping(value = "/", method = RequestMethod.POST)
  29. public void postAsyncUpdate() {
  30. myService.doAsync();
  31. }
  32. }
  33.  
  34. @Autowired
  35. private MyDbRepo myDbRepo;
  36.  
  37. @Async("threadTaskExecutor")
  38. public void doAsync() {
  39. if (!myDbRepo.isRunning()) {
  40. myDbRepo.setIsRunning(true);
  41. //Do Stuff
  42. myDbRepo.setIsRunning(false);
  43. } else {
  44. LOG.info("The Async task is already running");
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement