View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3820337#3820337
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3820337 FYI: Did some tests in AOP framework with object pooling through a ThreadLocal. I found that it actually slowed down performance by 20%. This finalizes what I've thought all along that Object pooling is worthless and it is better to let the VM handle it. Here's what I implemented: public class MethodInvocation extends Invocation { public Object[] arguments = null; // MARSHALLED public transient Method method = null; public long methodHash; public MethodInvocation(org.jboss.aop.advice.Interceptor[] interceptors) { super(InvocationType.METHOD, interceptors); } protected void clear() { super.clear(); arguments = null; } public static class Pool { private ThreadLocal pool = new ThreadLocal(); public MethodInvocation getInstance(Interceptor[] interceptors) { MethodInvocation[] pooled = (MethodInvocation[]) pool.get(); if (pooled == null) { System.out.println("returning new invocation"); return new MethodInvocation(interceptors); } MethodInvocation instance = null; for (int i = pooled.length - 1; i >= 0; i--) { if (pooled == null) continue; instance = pooled; pooled = null; break; } if (instance == null) { System.out.println("returning new invocation"); return new MethodInvocation(interceptors); } instance.interceptors = interceptors; return instance; } public void releaseInstance(MethodInvocation invocation) { invocation.clear(); MethodInvocation[] pooled = (MethodInvocation[]) pool.get(); if (pooled == null) { pooled = new MethodInvocation[1]; pooled[0] = invocation; pool.set(pooled); return; } int i = 0; for (; i < pooled.length; i++) { if (pooled == null) { pooled = invocation; return; } } // pool is too big MethodInvocation[] newPooled = new MethodInvocation[pooled.length + 1]; System.arraycopy(pooled, 0, newPooled, 0, pooled.length); newPooled[pooled.length] = invocation; pool.set(newPooled); } } } ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ JBoss-Development mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/jboss-development
