From 58b6f67674a6a9164c5097fb3d54434e3154d746 Mon Sep 17 00:00:00 2001 From: "koo.taejin" Date: Tue, 1 Dec 2015 15:11:49 +0900 Subject: [PATCH] #1257 Method caching to improve performance. --- .../Jetty8ServerHandleInterceptor.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/plugins/jetty/src/main/java/com/navercorp/pinpoint/plugin/jetty/interceptor/Jetty8ServerHandleInterceptor.java b/plugins/jetty/src/main/java/com/navercorp/pinpoint/plugin/jetty/interceptor/Jetty8ServerHandleInterceptor.java index 41daf7caa1df..0017c7838c4a 100644 --- a/plugins/jetty/src/main/java/com/navercorp/pinpoint/plugin/jetty/interceptor/Jetty8ServerHandleInterceptor.java +++ b/plugins/jetty/src/main/java/com/navercorp/pinpoint/plugin/jetty/interceptor/Jetty8ServerHandleInterceptor.java @@ -14,6 +14,8 @@ @TargetMethod(name = "handle", paramTypes = { "org.eclipse.jetty.server.AbstractHttpConnection" }) public class Jetty8ServerHandleInterceptor extends AbstractServerHandleInterceptor { + private volatile Method getRequestMethod; + public Jetty8ServerHandleInterceptor(TraceContext traceContext, MethodDescriptor descriptor, Filter excludeFilter) { super(traceContext, descriptor, excludeFilter); } @@ -23,7 +25,7 @@ protected Request getRequest(Object[] args) { try { Object object = args[0]; - Method getRequestMethod = getMethod(object.getClass(), "getRequest"); + Method getRequestMethod = getGetRequestMethod(object.getClass()); Request request = (Request) getRequestMethod.invoke(object); return request; } catch (Exception e) { @@ -33,24 +35,26 @@ protected Request getRequest(Object[] args) { return null; } - private Method getMethod(Class clazz, String methodName) { - Class targetClazz = clazz; + private Method getGetRequestMethod(Class clazz) { + if (getRequestMethod != null) { + return getRequestMethod; + } + + synchronized (this) { + if (getRequestMethod != null) { + return getRequestMethod; + } - while (targetClazz != null) { try { - Method method = targetClazz.getMethod(methodName); - if (method != null) { - return method; + Method findedMethod = clazz.getMethod("getRequest"); + if (findedMethod != null) { + getRequestMethod = findedMethod; + return getRequestMethod; } - } catch (NoSuchMethodException e) { - Class superclass = targetClazz.getSuperclass(); - if (superclass != null) { - targetClazz = superclass; - } + logger.warn(e.getMessage(), e); } } - return null; };