From 93548ceeb5c94139ac8be074a47f8d0a254ffe72 Mon Sep 17 00:00:00 2001 From: Victor Toni Date: Wed, 14 Aug 2024 18:40:11 +0200 Subject: [PATCH] Change event loop to use daemon instead of non-daemon threads The class io.netty.util.concurrent.DefaultThreadFactory defaults to non-daemon thread if not explicitly configured. Threads created with defaults by this ThreadFactory might prevent unaware applcations from quitting. --- .../hivemq/client/internal/netty/NettyEventLoopProvider.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/hivemq/client/internal/netty/NettyEventLoopProvider.java b/src/main/java/com/hivemq/client/internal/netty/NettyEventLoopProvider.java index 5ef5044c4..eb175d0d6 100644 --- a/src/main/java/com/hivemq/client/internal/netty/NettyEventLoopProvider.java +++ b/src/main/java/com/hivemq/client/internal/netty/NettyEventLoopProvider.java @@ -90,9 +90,10 @@ private NettyEventLoopProvider( if (entry == null) { final MultithreadEventLoopGroup eventLoopGroup; if (executor == null) { + final boolean useDaemonThreads = true; eventLoopGroup = eventLoopGroupFactory.apply( threadCount, new ThreadPerTaskExecutor( - new DefaultThreadFactory("com.hivemq.client.mqtt", Thread.MAX_PRIORITY))); + new DefaultThreadFactory("com.hivemq.client.mqtt", useDaemonThreads, Thread.MAX_PRIORITY))); } else if (executor instanceof MultithreadEventLoopGroup) { eventLoopGroup = (MultithreadEventLoopGroup) executor;