From c0a16a8522792d520d4a492f5f6c209f9f6806b3 Mon Sep 17 00:00:00 2001 From: smillies Date: Thu, 14 Sep 2017 11:59:19 +0200 Subject: [PATCH] The default executor service of java.io.concurrent.Future creates daemon threads --- vavr/src/main/java/io/vavr/concurrent/Future.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vavr/src/main/java/io/vavr/concurrent/Future.java b/vavr/src/main/java/io/vavr/concurrent/Future.java index 85ab5822f5..8fa6e93949 100644 --- a/vavr/src/main/java/io/vavr/concurrent/Future.java +++ b/vavr/src/main/java/io/vavr/concurrent/Future.java @@ -58,10 +58,14 @@ public interface Future extends Value { /** - * The default executor service is {@link Executors#newCachedThreadPool()}. - * Please note that it may prevent the VM from shutdown. - */ - ExecutorService DEFAULT_EXECUTOR_SERVICE = Executors.newCachedThreadPool(); + * The default executor service is {@link Executors#newCachedThreadPool()}. The service will create daemon threads, + * in order to avoid preventing the VM from shutdown. + */ + ExecutorService DEFAULT_EXECUTOR_SERVICE = Executors.newCachedThreadPool(runnable -> { + Thread thread = Executors.defaultThreadFactory().newThread(runnable); + thread.setDaemon(true); + return thread; + }); /** * Creates a failed {@code Future} with the given {@code exception}, backed by the {@link #DEFAULT_EXECUTOR_SERVICE}.