@Test public void executionOrderOneKey() throws Exception { int numberOfExecutions = 1000; MultiKeySequentialExecutor<String> executor = new MultiKeySequentialExecutor<>(2); IntList executionOrderCheckingList = new IntArrayList(); CompletableFuture<Boolean> lastFuture = null; for (int i = 0; i < numberOfExecutions; i++) { final int iFinal = i; lastFuture = executor.submit("myKey", () -> executionOrderCheckingList.add(iFinal)); } CompletableFuture<Void> allDoneFuture = lastFuture.thenRun(() -> { checkIntListContents(executionOrderCheckingList, numberOfExecutions); }); allDoneFuture.get(1, TimeUnit.SECONDS); }
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);  }