如何在 WebSphere Liberty 中设置方法级事务超时?

How to set Method level Transaction timeout in WebSphere Liberty?

我已经开发了 Java 应用程序并且正在使用 wlp18 服务器。在此之前,我有 运行 我的应用程序使用 Jboss。在 Jboss 中,我使用 @TransactionTimeout 批注在我的 EJB 中设置方法级事务超时。当我迁移到 WebSphere Liberty 时,我无法找到方法级事务超时。而不是使用 .xml 配置来设置 class 级事务超时,如下所示,

 <session name="class-name">
   <global-transaction transaction-time-out="1000">
 <session>

有什么方法可以在方法级别设置事务超时,或者为什么不能在 WebSphere Liberty 中设置方法级别事务。

如果您有权访问 UserTransaction 对象,则可以使用该对象设置事务超时:

@Resource
UserTransaction tx;

public void doSomething() {
  tx.setTransactionTimeout(123);
  tx.begin();
  // ...
}