Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TaskA implements Runnable {
- @Resource
- private TaskService taskService;
- @Override
- public void run() {
- // Run task A
- // ...
- // Set run ID for task B to retrieve
- taskService.setRunId("A", UUID.randomUUID().toString());
- }
- }
- public class TaskB implements Runnable {
- private static final Logger log = LoggerFactory.getLogger(TaskB.class);
- @Resource
- private TaskService taskService;
- private String lastId;
- @Override
- public void run() {
- String nextId = taskService.getRunId("A");
- if (this.lastId == null) {
- log.info("First run. Not executing");
- } else if (lastId.equals(nextId)) {
- log.warn("Task A has not run. Refusing to execute");
- } else {
- log.info("Executing");
- // Run task B
- // ...
- }
- this.lastId = nextId;
- }
- }
Add Comment
Please, Sign In to add comment