4

I need to create a EJB timer (using @Schedule), but have read that this is not supported in a Websphere Liberty profile? According to a previously posted question on StackOverflow, it wasn't supported as of 08/2013:

Java EE-Timer / @Schedule in Websphere Liberty Profile

Currently when I try to use the @Schedule annotation I get the following exception:

[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.

The problem is I DO have a default data source defined. Here is the EJB code - it is very simple because I was just trying to test out timer functionality:

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!");
    }

}

Update:

I changed my dataSource id to "DefaultDataSource", and now I am getting a different exceptions in my console when starting the server:

[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)

Is this the result of the timer attempting to write to my SQL DB, and if so, is there a way to avoid this?

Community
  • 1
  • 1
schuno
  • 545
  • 6
  • 11
  • Is the app starting even though you have these error messages? Or does this fail the application start process? – Andy Guibert Nov 11 '15 at 16:54
  • It was not starting because of the messages.. I since replaced ejb-3.2 with ejbLite-3.2 and put my database name back to what it was and everything is working correctly. – schuno Nov 11 '15 at 18:22

4 Answers4

5

It looks like you have the ejbPersistentTimer-3.2 feature turned on, since you are getting exceptions for having a DataSource configured.

If you are going to use ejbPersistentTimer-3.2 (or ejb-3.2 which includes it) you need to configure a datasource to be used for persistent timers.

Since you don't need persistent EJB timers (because you have persistent=false in your @Schedule annotation) you can remove the ejbPersistentTimer-3.2 feature and just use the ejbLite-3.2 feature (which doesn't include the persistent timer feature).

The ejbLite-3.2 feature includes support for non-persistent timers, and you won't need to worry about configuring a DataSource.

Andy Guibert
  • 41,446
  • 8
  • 38
  • 61
  • I am currently using the ejb-3.2 feature, which includes ejbPersistentTimer-3.2 (according the console output). So even when removing ejbPersistentTimer-3.2 I still get the same result. – schuno Nov 11 '15 at 16:33
  • @schuno I was referring to `ejbLite-3.2` not the full `ejb-3.2`. The Lite feature does not include persistent timers. – Andy Guibert Nov 11 '15 at 16:45
  • thank you! Once I changed from ejb-3.2 to ejbLite-3.2 it worked! – schuno Nov 11 '15 at 17:15
  • @aguibert can create a small example how to use non persistence timers. – Mindaugas Jaraminas Nov 22 '16 at 14:04
  • @Mindaugas an example of using non-persistent timers is shown in the OP. The key is having `@Schedule(.... persistent=false)` – Andy Guibert Nov 22 '16 at 15:07
1

EJB timers are supported with WAS Liberty provided you use 8.5.5.6 or newer which is fully compliant with Java EE 7.

Alasdair
  • 3,071
  • 15
  • 20
  • Hi Alasdair, I'm using version 8.5.57, so according to what you said this should be working. I changed my dataSource id to "DefaultDataSource", and now I am getting a new excpetion (I added the new exception as an "Update" to my original question). Thanks. – schuno Nov 10 '15 at 17:07
0
  1. Add a new Database Store and provide it a reference to a Data Source. If you don't have one for the EJB timer tables or want a distinct one you can create a Data Source underneath the Database Store. Ensure you provide it an ID
  2. Add EJB Container -> EJB Timer Service -> EJB Persistent Timers Scheduled Executor
  3. On the EJB Persistent Timers Scheduled Executor set the Persistent task store reference to the ID of the Database Store

That should get rid of the error and will not require you to switch to EJB Lite.

Archimedes Trajano
  • 35,625
  • 19
  • 175
  • 265
-1

From the IBM article at http://www.ibm.com/developerworks/websphere/library/techarticles/1404_vines1/1404_vines1.html, it looks like it is not available and you'll have to go third party:

The EJB Timer Service is not supported on Liberty profile or Liberty Core. If your application uses the EJB Timer Service, you can select one of these options: Deploy this part of your application in the WebSphere Application Server Full profile. Use other third-party scheduling libraries. Note: Although the second option is listed as a complex approach, its complexity can be simplified if a small number of timers are involved.

Update:

A little further research found this thread which seems to offer a solution (at least there's an accepted answer):

https://developer.ibm.com/answers/questions/187132/ejbpersistenttimer-32/

Mike
  • 159
  • 10