Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.List;
- import java.util.concurrent.CompletableFuture;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
- public class Main {
- public static void main(String[] args) {
- final BusinessEntity first = new BusinessEntity(1001, List.of(new Action(2, "Action2"), new Action(1, "Action1"), new Action(3, "Action3")));
- final BusinessEntity second = new BusinessEntity(1002, List.of(new Action(4, "Action4"), new Action(6, "Action6"), new Action(5, "Action5")));
- // todo: run 2 above business entities in parallel + each has a list of actions -> sort that list by priority (1, 2, 3...) and run sequentially according to priority with processAction() -> 1 - first, 2 - second...
- }
- public static CompletableFuture<String> processAction(final int entityId, final int priorityId, final String actionName) {
- return CompletableFuture.supplyAsync(() -> {
- System.out.printf("process entityId: %d, priorityId: %d, actionName: %s, in thread: %s%n",
- entityId, priorityId, actionName, Thread.currentThread().getName());
- return "DONE";
- });
- }
- public static class BusinessEntity {
- private final int entityId;
- private final List<Action> actions;
- public BusinessEntity(int entityId, List<Action> actions) {
- this.entityId = entityId;
- this.actions = actions;
- }
- }
- public static class Action {
- private final int priorityId;
- private final String actionName;
- public Action(int priorityId, String actionName) {
- this.priorityId = priorityId;
- this.actionName = actionName;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement