[英]Creating an EJB Timer in Liberty
我需要创建一个EJB计时器(使用@Schedule),但是已经读过Websphere Liberty配置文件中不支持这个? 根据之前在StackOverflow上发布的问题,截至2013年8月,它不受支持:
Websphere Liberty Profile中的Java EE-Timer / @Schedule
目前,当我尝试使用@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!");
}
}
更新:
我将我的dataSource 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 DB的结果,如果是,有没有办法避免这种情况?
看起来您已ejbPersistentTimer-3.2
功能,因为您在配置DataSource时遇到异常。
如果要使用ejbPersistentTimer-3.2
(或包含它的ejb-3.2
),则需要配置用于持久定时器的数据源。
由于您不需要持久性EJB计时器(因为您的@Schedule
注释中有persistent=false
),因此可以删除ejbPersistentTimer-3.2
功能并仅使用ejbLite-3.2
功能(不包括持久计时器功能)。
ejbLite-3.2
功能包括对非持久性计时器的支持,您无需担心配置数据源。
WAS Liberty支持EJB计时器,前提是您使用完全符合Java EE 7的8.5.5.6或更高版本。
ID
ID
这应该摆脱错误,不要求你切换到EJB Lite。
来自http://www.ibm.com/developerworks/websphere/library/techarticles/1404_vines1/1404_vines1.html上的IBM文章,看起来它不可用,你必须去第三方:
Liberty概要文件或Liberty Core不支持EJB计时器服务。 如果您的应用程序使用EJB Timer Service,您可以选择以下选项之一:在WebSphere Application Server Full配置文件中部署应用程序的这一部分。 使用其他第三方调度库。 注意:尽管第二个选项被列为复杂方法,但如果涉及少量定时器,则可以简化其复杂性。
更新:
进一步的研究发现这个线程似乎提供了一个解决方案(至少有一个公认的答案):
https://developer.ibm.com/answers/questions/187132/ejbpersistenttimer-32/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.