@Test public void cancel_shouldThrowAnUnsupportedOperationException_givenAFutureReturnedByExecute() throws Exception { Future<?> result = asyncExecutor.execute(() -> {}); try { result.cancel(true); fail("Expected an exception"); } catch (UnsupportedOperationException ignore) {} }
public Future<?> execute(Runnable runnable) { CompletableFuture<?> result = new CompletableFuture<Object>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { throw new UnsupportedOperationException("Calling thread.stop is deprecated. Arrange termination directly with the runnable"); } }; factory.newThread(() -> { try { runnable.run(); } finally { result.complete(null); } }).start(); return result; }
AsyncExecutor { public Future<?> execute(Runnable runnable) { CompletableFuture<?> result = new CompletableFuture<Object>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { throw new UnsupportedOperationException("Calling thread.stop is deprecated. Arrange termination directly with the runnable"); } }; factory.newThread(() -> { try { runnable.run(); } finally { result.complete(null); } }).start(); return result; } }
AsyncExecutor { public Future<?> execute(Runnable runnable) { CompletableFuture<?> result = new CompletableFuture<Object>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { throw new UnsupportedOperationException("Calling thread.stop is deprecated. Arrange termination directly with the runnable"); } }; factory.newThread(() -> { try { runnable.run(); } finally { result.complete(null); } }).start(); return result; } AsyncExecutor(ThreadFactory factory); }
AsyncExecutor { public Future<?> execute(Runnable runnable) { CompletableFuture<?> result = new CompletableFuture<Object>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { throw new UnsupportedOperationException("Calling thread.stop is deprecated. Arrange termination directly with the runnable"); } }; factory.newThread(() -> { try { runnable.run(); } finally { result.complete(null); } }).start(); return result; } AsyncExecutor(ThreadFactory factory); Future<?> execute(Runnable runnable); }
AsyncExecutor { public Future<?> execute(Runnable runnable) { CompletableFuture<?> result = new CompletableFuture<Object>() { @Override public boolean cancel(boolean mayInterruptIfRunning) { throw new UnsupportedOperationException("Calling thread.stop is deprecated. Arrange termination directly with the runnable"); } }; factory.newThread(() -> { try { runnable.run(); } finally { result.complete(null); } }).start(); return result; } AsyncExecutor(ThreadFactory factory); Future<?> execute(Runnable runnable);  }