You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2020/03/19 05:54:10 UTC

[skywalking] branch master updated: Make `CommandService` daemon to avoid blocking target application shutting down gracefully (#4541)

This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 967ed8f  Make `CommandService` daemon to avoid blocking target application shutting down gracefully (#4541)
967ed8f is described below

commit 967ed8f774a2625d543799b4e2b7c41b5dc511b5
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Thu Mar 19 13:53:54 2020 +0800

    Make `CommandService` daemon to avoid blocking target application shutting down gracefully (#4541)
---
 .../apm/agent/core/commands/CommandService.java    | 33 +++++++++++-----------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/commands/CommandService.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/commands/CommandService.java
index ed18f84..b502f03 100755
--- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/commands/CommandService.java
+++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/commands/CommandService.java
@@ -17,8 +17,13 @@
 
 package org.apache.skywalking.apm.agent.core.commands;
 
+import java.util.ArrayList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
 import org.apache.skywalking.apm.agent.core.boot.BootService;
 import org.apache.skywalking.apm.agent.core.boot.DefaultImplementor;
+import org.apache.skywalking.apm.agent.core.boot.DefaultNamedThreadFactory;
 import org.apache.skywalking.apm.agent.core.boot.ServiceManager;
 import org.apache.skywalking.apm.agent.core.logging.api.ILog;
 import org.apache.skywalking.apm.agent.core.logging.api.LogManager;
@@ -29,19 +34,16 @@ import org.apache.skywalking.apm.network.trace.component.command.CommandDeserial
 import org.apache.skywalking.apm.network.trace.component.command.UnsupportedCommandException;
 import org.apache.skywalking.apm.util.RunnableWithExceptionProtection;
 
-import java.util.ArrayList;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.LinkedBlockingQueue;
-
 @DefaultImplementor
 public class CommandService implements BootService, Runnable {
 
     private static final ILog LOGGER = LogManager.getLogger(CommandService.class);
 
     private volatile boolean isRunning = true;
-    private ExecutorService executorService = Executors.newSingleThreadExecutor();
-    private LinkedBlockingQueue<BaseCommand> commands = new LinkedBlockingQueue<BaseCommand>(64);
+    private ExecutorService executorService = Executors.newSingleThreadExecutor(
+        new DefaultNamedThreadFactory("CommandService")
+    );
+    private LinkedBlockingQueue<BaseCommand> commands = new LinkedBlockingQueue<>(64);
     private CommandSerialNumberCache serialNumberCache = new CommandSerialNumberCache();
 
     @Override
@@ -50,12 +52,9 @@ public class CommandService implements BootService, Runnable {
 
     @Override
     public void boot() throws Throwable {
-        executorService.submit(new RunnableWithExceptionProtection(this, new RunnableWithExceptionProtection.CallbackWhenException() {
-            @Override
-            public void handle(final Throwable t) {
-                LOGGER.error(t, "CommandService failed to execute commands");
-            }
-        }));
+        executorService.submit(
+            new RunnableWithExceptionProtection(this, t -> LOGGER.error(t, "CommandService failed to execute commands"))
+        );
     }
 
     @Override
@@ -94,7 +93,7 @@ public class CommandService implements BootService, Runnable {
     @Override
     public void shutdown() throws Throwable {
         isRunning = false;
-        commands.drainTo(new ArrayList<BaseCommand>());
+        commands.drainTo(new ArrayList<>());
         executorService.shutdown();
     }
 
@@ -111,8 +110,10 @@ public class CommandService implements BootService, Runnable {
                 boolean success = this.commands.offer(baseCommand);
 
                 if (!success && LOGGER.isWarnEnable()) {
-                    LOGGER.warn("Command[{}, {}] cannot add to command list. because the command list is full.", baseCommand
-                        .getCommand(), baseCommand.getSerialNumber());
+                    LOGGER.warn(
+                        "Command[{}, {}] cannot add to command list. because the command list is full.",
+                        baseCommand.getCommand(), baseCommand.getSerialNumber()
+                    );
                 }
             } catch (UnsupportedCommandException e) {
                 if (LOGGER.isWarnEnable()) {