java - 在 Liberty 中创建 EJB 计时器

标签 java jakarta-ee timer ejb websphere-liberty

我需要创建一个 EJB 计时器(使用 @Schedule),但是我听说 Websphere Liberty 配置文件不支持它吗?根据之前在 StackOverflow 上发布的问题,截至 08/2013 不支持它:

Java EE-Timer / @Schedule in Websphere Liberty Profile

目前,当我尝试使用 @Schedule 注释时,出现以下异常:

[ERROR   ] CWWKZ0004E: An exception occurred while starting the application 
<EAR>. The exception message was: com.ibm.ws.container.service.state.StateChangeException: com.ibm.ws.exception.RuntimeError: java.lang.IllegalStateException: The ejbPersistentTimer feature is enabled, but the defaultEJBPersistentTimerExecutor persistent executor cannot be resolved. The most likely cause is that the DefaultDataSource datasource has not been configured. Persistent EJB timers require a datasource configuration for persistence.

问题是我确实定义了默认数据源。这是 EJB 代码 - 它非常简单,因为我只是想测试计时器功能:

import javax.ejb.Schedule;
import javax.ejb.Stateless;

@Stateless
public class TimerBean {

    @Schedule(second="*/10", persistent=false)
    public void doSomething() {
        System.out.println("Hello World!");
    }

}

更新:

我将我的数据源 ID 更改为“DefaultDataSource”,现在启动服务器时我的控制台出现了不同的异常:

[ERROR   ] WTRN0078E: An attempt by the transaction manager to call start on a transactional resource has resulted in an error. The error code was XAER_RMERR. The exception stack trace follows: javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'master..xp_sqljdbc_xa_start'.
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.DTC_XA_Interface(SQLServerXAResource.java:647)
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.start(SQLServerXAResource.java:679)
at com.ibm.ws.rsadapter.spi.WSRdbXaResourceImpl.start(WSRdbXaResourceImpl.java:1189)
at [internal classes]

[ERROR   ] J2CA0030E: Method enlist caught javax.transaction.SystemException: XAResource start association error:XAER_RMERR
at com.ibm.tx.jta.impl.RegisteredResources.startRes(RegisteredResources.java:1048)
at [internal classes]
Caused by: javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Could not find stored procedure 'master..xp_sqljdbc_xa_start'.
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.DTC_XA_Interface(SQLServerXAResource.java:647)
at com.microsoft.sqlserver.jdbc.SQLServerXAResource.start(SQLServerXAResource.java:679)

这是计时器尝试写入我的 SQL 数据库的结果吗?如果是,是否有办法避免这种情况?

最佳答案

看起来您打开了 ejbPersistentTimer-3.2 功能,因为您正在获取配置数据源的异常。

如果您打算使用 ejbPersistentTimer-3.2(或包含它的 ejb-3.2),您需要配置一个数据源以用于持久计时器。

由于您不需要永久性 EJB 计时器(因为您在 @Schedule 注释中有 persistent=false),您可以删除 ejbPersistentTimer-3.2 功能并仅使用 ejbLite-3.2 功能(不包括持久计时器功能)。

ejbLite-3.2 功能包括对非持久计时器的支持,您无需担心配置数据源的问题。

关于java - 在 Liberty 中创建 EJB 计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33631860/

相关文章:

c++ - 如何与程序的其余部分同时显示计时器?

c - 在 C 中跟踪任务的执行时间(忽略时间任务被挂起)

java - 接口(interface)方法可以重载吗?

java - JSP 使用服务器时区显示服务器日期和时间

java - 一个应用程序中的数据库连接泄漏是否会影响服务器中的其他应用程序?

java - JEE Restful 将 JSON 绑定(bind)到 JAVA

matlab - 在循环内使用计时器

java - 如何加密mysql中的某些表

java - FileWriter 输出到 csv 文件为空

java - 在 Apache Tomcat 服务器 7.0 中部署 PHP 和 Java EE 应用程序