This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.0 by this push:
new 7e8c7aaca7 Add shutdown hook ignore support (#10029)
7e8c7aaca7 is described below
commit 7e8c7aaca76b0577dde10594798ee08736e0e2e4
Author: Albumen Kevin <[email protected]>
AuthorDate: Thu May 12 15:57:49 2022 +0800
Add shutdown hook ignore support (#10029)
---
.../apache/dubbo/common/constants/CommonConstants.java | 2 ++
.../java/org/apache/dubbo/config/DubboShutdownHook.java | 17 ++++++++++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
index 6e60942c52..861892df7f 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/constants/CommonConstants.java
@@ -535,4 +535,6 @@ public interface CommonConstants {
String NATIVE_STUB = "nativestub";
String METADATA = "metadata";
+
+ String IGNORE_LISTEN_SHUTDOWN_HOOK = "dubbo.shutdownHook.listenIgnore";
}
diff --git
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
index 9fa94b24ca..8989d882a2 100644
---
a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
+++
b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java
@@ -16,6 +16,8 @@
*/
package org.apache.dubbo.config;
+import org.apache.dubbo.common.config.ConfigurationUtils;
+import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.utils.Assert;
@@ -45,16 +47,25 @@ public class DubboShutdownHook extends Thread {
*/
private final AtomicBoolean destroyed = new AtomicBoolean(false);
+ /**
+ * Whether ignore listen on shutdown hook?
+ */
+ private final boolean ignoreListenShutdownHook;
+
public DubboShutdownHook(ApplicationModel applicationModel) {
super("DubboShutdownHook");
this.applicationModel = applicationModel;
Assert.notNull(this.applicationModel, "ApplicationModel is null");
+ ignoreListenShutdownHook =
Boolean.parseBoolean(ConfigurationUtils.getProperty(applicationModel,
CommonConstants.IGNORE_LISTEN_SHUTDOWN_HOOK));
+ if (ignoreListenShutdownHook) {
+ logger.info("dubbo.shutdownHook.listenIgnore configured, will
ignore add shutdown hook to jvm.");
+ }
}
@Override
public void run() {
- if (destroyed.compareAndSet(false, true)) {
+ if (destroyed.compareAndSet(false, true) && !ignoreListenShutdownHook)
{
if (logger.isInfoEnabled()) {
logger.info("Run shutdown hook now.");
}
@@ -71,7 +82,7 @@ public class DubboShutdownHook extends Thread {
* Register the ShutdownHook
*/
public void register() {
- if (registered.compareAndSet(false, true)) {
+ if (registered.compareAndSet(false, true) &&
!ignoreListenShutdownHook) {
try {
Runtime.getRuntime().addShutdownHook(this);
} catch (IllegalStateException e) {
@@ -86,7 +97,7 @@ public class DubboShutdownHook extends Thread {
* Unregister the ShutdownHook
*/
public void unregister() {
- if (registered.compareAndSet(true, false)) {
+ if (registered.compareAndSet(true, false) &&
!ignoreListenShutdownHook) {
if (this.isAlive()) {
// DubboShutdownHook thread is running
return;