From b7f1440254cf470fec409c3aed6c109b91c1c916 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Sat, 17 Jul 2010 21:08:41 +0000 Subject: [PATCH] performance optimization. --- .../general/ThreadSpecificProxyFactory.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/support/general/src/main/java/org/wamblee/general/ThreadSpecificProxyFactory.java b/support/general/src/main/java/org/wamblee/general/ThreadSpecificProxyFactory.java index 00856b10..51d23abf 100644 --- a/support/general/src/main/java/org/wamblee/general/ThreadSpecificProxyFactory.java +++ b/support/general/src/main/java/org/wamblee/general/ThreadSpecificProxyFactory.java @@ -53,8 +53,9 @@ public class ThreadSpecificProxyFactory { } } - private ThreadLocal svc = new ThreadLocal(); + private ThreadLocal svc; private Class clazz; + private T proxy; /** * Constructs the factory. @@ -67,7 +68,9 @@ public class ThreadSpecificProxyFactory { throw new IllegalArgumentException("Class " + aClass.getName() + " is not an interface"); } + svc = new ThreadLocal(); clazz = aClass; + proxy = createProxy(); } /** @@ -97,15 +100,19 @@ public class ThreadSpecificProxyFactory { * @return Proxy. */ public T getProxy() { + return proxy; + } + + private T createProxy() { InvocationHandler handler = new ThreadSpecificInvocationHandler(); Class proxyClass = Proxy.getProxyClass(clazz.getClassLoader(), new Class[] { clazz }); - T proxy; + T proxyObj; try { - proxy = (T) proxyClass.getConstructor( + proxyObj = (T) proxyClass.getConstructor( new Class[] { InvocationHandler.class }).newInstance( new Object[] { handler }); - return proxy; + return proxyObj; } catch (Exception e) { throw new RuntimeException("Could not create proxy for " + clazz.getName(), e); -- 2.31.1