diff --git a/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java b/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java index 5fa1113963558..1147572ecc9bf 100644 --- a/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java +++ b/extensions/apicurio-registry-avro/deployment/src/main/java/io/quarkus/apicurio/registry/avro/DevServicesApicurioRegistryProcessor.java @@ -102,14 +102,6 @@ public void run() { }; QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader(); ((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask); - Thread closeHookThread = new Thread(closeTask, "Apicurio Registry container shutdown thread"); - Runtime.getRuntime().addShutdownHook(closeHookThread); - ((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().removeShutdownHook(closeHookThread); - } - }); } } diff --git a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java index ca64741b09ea0..0881c79369314 100644 --- a/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java +++ b/extensions/datasource/deployment/src/main/java/io/quarkus/datasource/deployment/devservices/DevServicesDatasourceProcessor.java @@ -161,14 +161,6 @@ public void run() { }; QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader(); ((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask); - Thread closeHookThread = new Thread(closeTask, "Database shutdown thread"); - Runtime.getRuntime().addShutdownHook(closeHookThread); - ((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().removeShutdownHook(closeHookThread); - } - }); } databases = closeableList; cachedProperties = propertiesMap; diff --git a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java index 30e46fcd31410..34415afe512c0 100644 --- a/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java +++ b/extensions/kafka-client/deployment/src/main/java/io/quarkus/kafka/client/deployment/DevServicesKafkaProcessor.java @@ -111,9 +111,6 @@ public DevServicesKafkaBrokerBuildItem startKafkaDevService( }; QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader(); ((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask); - Thread closeHookThread = new Thread(closeTask, "Kafka container shutdown thread"); - Runtime.getRuntime().addShutdownHook(closeHookThread); - ((QuarkusClassLoader) cl.parent()).addCloseTask(() -> Runtime.getRuntime().removeShutdownHook(closeHookThread)); } cfg = configuration; diff --git a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java index 24b8183673f4e..1564f2fbbf38f 100644 --- a/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java +++ b/extensions/mongodb-client/deployment/src/main/java/io/quarkus/mongodb/deployment/DevServicesMongoProcessor.java @@ -117,14 +117,6 @@ public void run() { }; QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader(); ((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask); - Thread closeHookThread = new Thread(closeTask, "Mongo container shutdown thread"); - Runtime.getRuntime().addShutdownHook(closeHookThread); - ((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().removeShutdownHook(closeHookThread); - } - }); } closeables = currentCloseables; capturedProperties = currentCapturedProperties; diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java index 3e053fb929029..74791296bc745 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/devservices/keycloak/KeycloakDevServicesProcessor.java @@ -160,14 +160,6 @@ public void run() { }; QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader(); ((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask); - Thread closeHookThread = new Thread(closeTask, "Keycloak container shutdown thread"); - Runtime.getRuntime().addShutdownHook(closeHookThread); - ((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().removeShutdownHook(closeHookThread); - } - }); } capturedKeycloakUrl = startResult.url + "/auth"; diff --git a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java index 8d55ad11c6e4c..52a73e09abfeb 100644 --- a/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java +++ b/extensions/redis-client/deployment/src/main/java/io/quarkus/redis/client/deployment/DevServicesRedisProcessor.java @@ -117,9 +117,6 @@ public void startRedisContainers(LaunchModeBuildItem launchMode, }; QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader(); ((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask); - Thread closeHookThread = new Thread(closeTask, "Redis container shutdown thread"); - Runtime.getRuntime().addShutdownHook(closeHookThread); - ((QuarkusClassLoader) cl.parent()).addCloseTask(() -> Runtime.getRuntime().removeShutdownHook(closeHookThread)); } } diff --git a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java index 4dd81decd3c61..5031d9c77c8a6 100644 --- a/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java +++ b/extensions/smallrye-reactive-messaging-amqp/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/amqp/deployment/DevServicesAmqpProcessor.java @@ -107,9 +107,6 @@ public DevServicesAmqpBrokerBuildItem startAmqpDevService( }; QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader(); ((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask); - Thread closeHookThread = new Thread(closeTask, "AMQP container shutdown thread"); - Runtime.getRuntime().addShutdownHook(closeHookThread); - ((QuarkusClassLoader) cl.parent()).addCloseTask(() -> Runtime.getRuntime().removeShutdownHook(closeHookThread)); } cfg = configuration; return artemis; diff --git a/extensions/vault/deployment/src/main/java/io/quarkus/vault/deployment/DevServicesVaultProcessor.java b/extensions/vault/deployment/src/main/java/io/quarkus/vault/deployment/DevServicesVaultProcessor.java index a76c25835fe24..0d897b7f31075 100644 --- a/extensions/vault/deployment/src/main/java/io/quarkus/vault/deployment/DevServicesVaultProcessor.java +++ b/extensions/vault/deployment/src/main/java/io/quarkus/vault/deployment/DevServicesVaultProcessor.java @@ -93,14 +93,6 @@ public void run() { }; QuarkusClassLoader cl = (QuarkusClassLoader) Thread.currentThread().getContextClassLoader(); ((QuarkusClassLoader) cl.parent()).addCloseTask(closeTask); - Thread closeHookThread = new Thread(closeTask, "Vault container shutdown thread"); - Runtime.getRuntime().addShutdownHook(closeHookThread); - ((QuarkusClassLoader) cl.parent()).addCloseTask(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().removeShutdownHook(closeHookThread); - } - }); } for (Map.Entry entry : connectionProperties.entrySet()) { devConfig.produce(new DevServicesConfigResultBuildItem(entry.getKey(), entry.getValue())); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java index fba678a1b19cd..7daaf031e8a3f 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java @@ -338,6 +338,7 @@ public Thread newThread(Runnable r) { .setTest(true) .build() .bootstrap(); + shutdownTasks.add(curatedApplication::close); } if (curatedApplication.getAppModel().getUserDependencies().isEmpty()) { @@ -1260,7 +1261,11 @@ public void close() { ConfigProviderResolver.setInstance(null); } } - Runtime.getRuntime().removeShutdownHook(shutdownHook); + try { + Runtime.getRuntime().removeShutdownHook(shutdownHook); + } catch (Throwable t) { + //won't work if we are already shutting down + } } } }