performance optimization.
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sat, 17 Jul 2010 21:08:41 +0000 (21:08 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Sat, 17 Jul 2010 21:08:41 +0000 (21:08 +0000)
support/general/src/main/java/org/wamblee/general/ThreadSpecificProxyFactory.java

index 00856b100e4e1b8cd47db3813aa67ad0e7db3238..51d23abf46fd54484ff002f776c8a93c5f8df384 100644 (file)
@@ -53,8 +53,9 @@ public class ThreadSpecificProxyFactory<T> {
         }
     }
 
-    private ThreadLocal<T> svc = new ThreadLocal<T>();
+    private ThreadLocal<T> svc;
     private Class clazz;
+    private T proxy; 
 
     /**
      * Constructs the factory.
@@ -67,7 +68,9 @@ public class ThreadSpecificProxyFactory<T> {
             throw new IllegalArgumentException("Class " + aClass.getName() +
                 " is not an interface");
         }
+        svc = new ThreadLocal<T>();
         clazz = aClass;
+        proxy = createProxy(); 
     }
 
     /**
@@ -97,15 +100,19 @@ public class ThreadSpecificProxyFactory<T> {
      * @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);