I am rapidly developing with odejava and I was getting crashes now and again. I feared it was my thread safety so I wanted to quickly fix this problem. Here is my quick and pretty cool solution using jboss's AOP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| package testApp.aop;
import org.jboss.aop.advice.Interceptor; import org.jboss.aop.joinpoint.Invocation; import org.jboss.aop.joinpoint.MethodInvocation;
public class ThreadSafer implements Interceptor { public String getName() { return "testApp.aop.ThreadSafer"; }
public Object invoke(Invocation invocation) throws Throwable { try { MethodInvocation mi = (MethodInvocation) invocation; synchronized(this){ return invocation.invokeNext(); } } finally { } } } |
and the configuration for that is
1 2 3 4 5
| <aop> <bind pointcut="execution(* org.odejava*->*(..))"> <interceptor class="testApp.aop.ThreadSafer"/> </bind> </aop> |
And since doing that I have significantly reduced the amounts of non deterministic crashes I am getting from ode.
you can get AOP from jboss's website jboss.org