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.
package testApp.aop;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.joinpoint.Invocation;
import org.jboss.aop.joinpoint.MethodInvocation;
/**
* Created by IntelliJ IDEA.
* User: Tom
* Date: 27-Jul-2004
* Time: 19:51:41
*/
public class ThreadSafer implements Interceptor {
public String getName() {
return "testApp.aop.ThreadSafer";
}
public Object invoke(Invocation invocation) throws Throwable {
try {
MethodInvocation mi = (MethodInvocation) invocation;
//System.out.println("<<< Entering MethodInterceptor for: " + mi.getMethod().toString());
synchronized(this){
return invocation.invokeNext();
}
} finally {
//System.out.println(">>> Leaving MethodInterceptor");
}
}
}
and the configuration for that is
<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