Guest User

Untitled

a guest
Nov 20th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public class TaskA implements Runnable {
  2. @Resource
  3. private TaskService taskService;
  4.  
  5. @Override
  6. public void run() {
  7. // Run task A
  8. // ...
  9.  
  10. // Set run ID for task B to retrieve
  11. taskService.setRunId("A", UUID.randomUUID().toString());
  12. }
  13. }
  14.  
  15. public class TaskB implements Runnable {
  16. private static final Logger log = LoggerFactory.getLogger(TaskB.class);
  17.  
  18. @Resource
  19. private TaskService taskService;
  20.  
  21. private String lastId;
  22.  
  23. @Override
  24. public void run() {
  25. String nextId = taskService.getRunId("A");
  26. if (this.lastId == null) {
  27. log.info("First run. Not executing");
  28. } else if (lastId.equals(nextId)) {
  29. log.warn("Task A has not run. Refusing to execute");
  30. } else {
  31. log.info("Executing");
  32. // Run task B
  33. // ...
  34. }
  35. this.lastId = nextId;
  36. }
  37. }
Add Comment
Please, Sign In to add comment