Events CDI事件发起人';s事务等待观察者(成功后)事务?
我有以下场景:(pesudo代码)Events CDI事件发起人';s事务等待观察者(成功后)事务?,events,jakarta-ee,transactions,ejb,cdi,Events,Jakarta Ee,Transactions,Ejb,Cdi,我有以下场景:(pesudo代码) CallerObject.method(){ SessionBean1.method1();//通过远程bean接口 // [1] } @TransactionAttribute(必需) SessionBean1.method1(){ //做点什么。。。 事件。火灾(); //做点什么。。。 } method2(@Observes(during=AFTER_SUCCESS)myClass){ sessionBean2.method2();//通过本地bean接
CallerObject.method(){
SessionBean1.method1();//通过远程bean接口
// [1]
}
@TransactionAttribute(必需)
SessionBean1.method1(){
//做点什么。。。
事件。火灾();
//做点什么。。。
}
method2(@Observes(during=AFTER_SUCCESS)myClass){
sessionBean2.method2();//通过本地bean接口
}
@异步的
@TransactionAttribute(必需)
SessionBean2.method2(){
//做点什么。。。
}
==>发生以下情况:
[1] 仅在SessionBean2.method2()中的事务完成后才能到达!(尽管SessionBean1.method1()中的最后一条语句是在这之前到达的。)
这就好像SessionBean1.method1()的事务在异步调用的Session2.method2()的事务也完成之前没有以某种方式“释放”(因为缺少更好的词——它确实会在调用事件处理程序ObserverObject.method2()之前立即提交!)
有人知道我怎样才能避免吗
(整个设置的要点是让长期运行的SessionBean2.method2()
在T1完成后在后台运行,并让SessionBean1.method1()
尽快返回。)
附言:我已经证实了这一点
a) T1立即提交(记录进入数据库)
b) 异步调用SessionBean2.method2()(控件立即跳转到调用代码中的下一条语句)
c) 直到T2结束,SessionBean1.method1()才会将控制权返回给调用方代码
CallerObject.method() {
SessionBean1.method1(); // through remote bean interface
// [1]
}
@TransactionAttribute(REQUIRED)
SessionBean1.method1() {
// do something...
Event<myClass>.fire();
// do something...
}
ObserverObject.method2(@Observes(during=AFTER_SUCCESS) myClass) {
sessionBean2.method2(); // through local bean interface
}
@Asynchronous
@TransactionAttribute(REQUIRED)
SessionBean2.method2() {
// do something...
}