我在 Wildfly 10.10 中运行的单例 EJB 中有一个 EJB 计时器计划:
@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class MySingletonBean {
public method() {
//uses synchronization primitives to fine control the concurrent access
}
@Schedule(hour = "*", minute = "*", second = "*", persistent = false)
public void update() {
//each 120 seconds update method timeouts and the overlapping/log message occurs
}
}
Run Code Online (Sandbox Code Playgroud)
update() 模型中的任务运行流畅,大部分时间不到 1 秒。然而每2分钟,由于业务需要,该方法超时花费超过1秒。
问题:
每 2 分钟wildfly 输出一条日志消息,如:
(EJB 默认值 - 1)WFLYEJB0043:定时器 [] 的先前执行仍在进行中,跳过此重叠的计划执行:
我很清楚这条消息的含义:在下一次执行开始之前前一个计时器没有完成并且发生重叠。
此外,重叠会在正在更新的基础数据结构中引发并发问题。
我的问题:
1 - 如何在计时器缓慢的情况下放弃下一个计划以避免重叠/并发更新?
2 - …
我正在阅读 Java EE 7 的事务管理,但对嵌套事务的概念和EJBContext#setRollbackOnly()
.
说我有两个会话bean,Bean1Impl
并Bean2Impl
和他们的签名是:
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class Bean1Impl implements Bean1 {
@Resource
private EJBContext context;
@TransactionAttribute(REQUIRED)
public void method1() {
try {
//some operations such as persist(), merge() or remove().
}catch(Throwable th){
context.setRollbackOnly();
}
}
}
@Stateless
@TransactionManagement(TransactionManagementType.CONTAINER)
public class Bean2Impl implements Bean2 {
@Resource
private EJBContext context;
@TransactionAttribute(REQUIRED)
public void method2() {
try {
//some operations such as persist(), merge() or remove().
//an exception has been thrown
}catch(Throwable th){
context.setRollbackOnly(); …
Run Code Online (Sandbox Code Playgroud)