Java 8 Threads with CompletableFuture: Shutdown after supplyAsync()?

gene b. :

Suppose I'm running an async thread as follows,

SubmissionSupplier supplier = new SubmissionSupplier();
SubmissionConsumer consumer = new SubmissionConsumer();
CompletableFuture<Void> completableFuture = 
   CompletableFuture.supplyAsync(supplier).thenAccept(consumer);
// END, No further code

Do I need to do any shutdown to prevent memory leaks after this block? When I was using ExecutorService I had to do service.shutdown().

John Kugelman :

Nope. If you don't provide an executor to supplyAsync then it uses the fork-join common pool which does not need to be started or stopped. In fact, it can't be stopped.

This pool is statically constructed; its run state is unaffected by attempts to shutdown() or shutdownNow().

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=116600&siteId=1