From c3145e0e758ad291f710de8268f2dee3e05362f4 Mon Sep 17 00:00:00 2001 From: Michael Simons Date: Mon, 14 Jun 2021 14:32:46 +0200 Subject: [PATCH] Daemonize event loop threads. (#918) This instructs the `EventLoopGroupFactory` to daemonize newly created event loop group threads as per Netty's `DefaultThreadFactory`. This allows applications to shutdown when the last user thread ends, without explicitly calling `close` to the Neo4j driver instance, which is in line with other database drivers such as Postgres JDBC or MySQL JDBC. In addition, this might become relevant with Netty 5 at some point in the future, too. See: https://github.com/netty/netty/issues/2832. --- .../internal/async/connection/EventLoopGroupFactory.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/driver/src/main/java/org/neo4j/driver/internal/async/connection/EventLoopGroupFactory.java b/driver/src/main/java/org/neo4j/driver/internal/async/connection/EventLoopGroupFactory.java index 24b9e79911..600b45630d 100644 --- a/driver/src/main/java/org/neo4j/driver/internal/async/connection/EventLoopGroupFactory.java +++ b/driver/src/main/java/org/neo4j/driver/internal/async/connection/EventLoopGroupFactory.java @@ -40,6 +40,7 @@ public final class EventLoopGroupFactory { private static final String THREAD_NAME_PREFIX = "Neo4jDriverIO"; private static final int THREAD_PRIORITY = Thread.MAX_PRIORITY; + private static final boolean THREAD_IS_DAEMON = true; private EventLoopGroupFactory() { @@ -127,7 +128,7 @@ private static class DriverThreadFactory extends DefaultThreadFactory { DriverThreadFactory() { - super( THREAD_NAME_PREFIX, THREAD_PRIORITY ); + super( THREAD_NAME_PREFIX, THREAD_IS_DAEMON, THREAD_PRIORITY ); } @Override