From: erik Date: Sat, 17 Jul 2010 21:08:41 +0000 (+0000) Subject: performance optimization. X-Git-Tag: wamblee-utils-0.3~23 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=3bb08537dfc8212645edd99b955995e96f5ec8b6;p=utils performance optimization. --- 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);