@Test public void executionOrderMultipleKey() throws Exception { int numberOfExecutions = 1000; MultiKeySequentialExecutor<String> executor = new MultiKeySequentialExecutor<>(2); IntList executionOrderCheckingList1 = new IntArrayList(); IntList executionOrderCheckingList2 = new IntArrayList(); IntList executionOrderCheckingList3 = new IntArrayList(); CompletableFuture<Boolean> lastFuture1 = null; CompletableFuture<Boolean> lastFuture2 = null; CompletableFuture<Boolean> lastFuture3 = null; for (int i = 0; i < numberOfExecutions; i++) { final int iFinal = i; lastFuture1 = executor.submit("myKey1", () -> executionOrderCheckingList1.add(iFinal)); lastFuture2 = executor.submit("myKey2", () -> executionOrderCheckingList2.add(iFinal)); lastFuture3 = executor.submit("myKey3", () -> executionOrderCheckingList3.add(iFinal)); } CompletableFuture.allOf( lastFuture1.thenRun(() -> { checkIntListContents(executionOrderCheckingList1, numberOfExecutions); }), lastFuture2.thenRun(() -> { checkIntListContents(executionOrderCheckingList2, numberOfExecutions); }), lastFuture3.thenRun(() -> { checkIntListContents(executionOrderCheckingList3, numberOfExecutions); }) ) .get(); }
public CompletableFuture<Void> submit(K key, Runnable task) { return sequentialExecutors.computeIfAbsent(key, k -> new SequentialExecutor()) .submit(task); }
MultiKeySequentialExecutor { public CompletableFuture<Void> submit(K key, Runnable task) { return sequentialExecutors.computeIfAbsent(key, k -> new SequentialExecutor()) .submit(task); } }
MultiKeySequentialExecutor { public CompletableFuture<Void> submit(K key, Runnable task) { return sequentialExecutors.computeIfAbsent(key, k -> new SequentialExecutor()) .submit(task); } MultiKeySequentialExecutor(int nThreads);  MultiKeySequentialExecutor(ExecutorService executorService); }
MultiKeySequentialExecutor { public CompletableFuture<Void> submit(K key, Runnable task) { return sequentialExecutors.computeIfAbsent(key, k -> new SequentialExecutor()) .submit(task); } MultiKeySequentialExecutor(int nThreads);  MultiKeySequentialExecutor(ExecutorService executorService); CompletableFuture<Void> submit(K key, Runnable task); CompletableFuture<V> submit(K key, Supplier<V> task); void closeForKey(K key); SequentialExecutor getExecutorForKey(K key); }
MultiKeySequentialExecutor { public CompletableFuture<Void> submit(K key, Runnable task) { return sequentialExecutors.computeIfAbsent(key, k -> new SequentialExecutor()) .submit(task); } MultiKeySequentialExecutor(int nThreads);  MultiKeySequentialExecutor(ExecutorService executorService); CompletableFuture<Void> submit(K key, Runnable task); CompletableFuture<V> submit(K key, Supplier<V> task); void closeForKey(K key); SequentialExecutor getExecutorForKey(K key);  }