This is an automated email from the ASF dual-hosted git repository. wusheng pushed a commit to branch 5.x in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git
The following commit(s) were added to refs/heads/5.x by this push: new d494457 fix classloader dead lock in jdk7+ - 5.x (#2018) d494457 is described below commit d4944575bb556af58911e7f03f44ea366b3ca255 Author: caoyixiong <32847163+ian...@users.noreply.github.com> AuthorDate: Fri Dec 7 17:09:42 2018 +0800 fix classloader dead lock in jdk7+ - 5.x (#2018) --- .../agent/core/plugin/loader/AgentClassLoader.java | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java index 638fed0..b9f12c2 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/plugin/loader/AgentClassLoader.java @@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; +import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.Enumeration; @@ -45,6 +46,11 @@ import org.apache.skywalking.apm.agent.core.plugin.PluginBootstrap; * @author wusheng */ public class AgentClassLoader extends ClassLoader { + + static { + tryRegisterAsParallelCapable(); + } + private static final ILog logger = LogManager.getLogger(AgentClassLoader.class); /** * The default class loader for the agent. @@ -55,6 +61,28 @@ public class AgentClassLoader extends ClassLoader { private List<Jar> allJars; private ReentrantLock jarScanLock = new ReentrantLock(); + /** + * Functional Description: solve the classloader dead lock when jvm start + * only support JDK7+, since ParallelCapable appears in JDK7+ + */ + private static void tryRegisterAsParallelCapable() { + Method[] methods = ClassLoader.class.getDeclaredMethods(); + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; + String methodName = method.getName(); + if ("registerAsParallelCapable".equalsIgnoreCase(methodName)) { + try { + method.setAccessible(true); + method.invoke(null); + } catch (Exception e) { + logger.warn(e, "can not invoke ClassLoader.registerAsParallelCapable()"); + } + return; + } + } + } + + public static AgentClassLoader getDefault() { return DEFAULT_LOADER; }