0

I have created an EJB Timer like this:

@Stateless
public class MyTimerService {


@Schedule(second="*/10", minute="*", hour="*", dayOfMonth="*", persistent=false)
public void process() {
     logger.info("Start processing")
}
}

and I am deploying it on Websphere 8.5. As I know, WAS 8.5 implements the Java EE 6 specification, so it should work, however it does not. It looks like the server does not start the timer at application start up. What am I doing wrong?

UPDATE: I also annotated MyTimerService with @Startup + @Singleton, the bean is started when the application starts but the timer does not start either.

Matei Florescu
  • 1,155
  • 11
  • 23
  • Have you tried injecting the EJB TimerService like such: `@Resource` `TimerService timerService;` Then, within your process method: `TimerConfig timerConfig = new TimerConfig();` `timerConfig.setInfo("OCIClientKeepAlive Timer");` `timerConfig.setPersistent(false);` `timerService.createIntervalTimer(new Date(), timerInterval, timerConfig);` Apologize on the formatting - If it works I'll add it as an answer! – JGlass Jan 12 '18 at 15:23
  • 1
    No, I have not, but I want to run with annotations. – Matei Florescu Jan 12 '18 at 15:28
  • [Here's](https://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html) an example from Oracle, and [here's](http://www.baeldung.com/scheduling-in-java-enterprise-edition) one from Baeldung - they both either inject a `Event` or use a TimerService resource - mine works, but I used the Timer config which I probably didnt need to do – JGlass Jan 12 '18 at 15:38
  • The second answer down in [this](https://stackoverflow.com/questions/15973661/dynamic-parameters-for-schedule-method-in-an-ejb-3-x) SO post also shows similar to what I'm doing. It uses a @PostConstruct but I'm still thinking you might need a TimerService injected Resource - but I may be completely wrong as [this](https://stackoverflow.com/questions/13529131/schedule-can%C2%B4t-inject-ejb?rq=1) seems to work but in JBoss - maybe a WebSphere thing? – JGlass Jan 12 '18 at 15:46
  • 1
    In the Baeldung example you posted there are some examples that use the @Schedule annotation without injecting the TimerService. I don't think injecting is necessary. – Matei Florescu Jan 12 '18 at 15:50
  • [Looks](https://www.ibm.com/support/knowledgecenter/en/SSAW57_8.5.5/com.ibm.websphere.nd.doc/ae/tejb_timerserviceejb_enh.html) like you're right, my apologies - though I may have missed something as its a very lenghty article. – JGlass Jan 12 '18 at 15:56
  • Is your WebSphere newer than 8.5.5.6 or is it an older version? – JGlass Jan 12 '18 at 16:17
  • I just tested your code snippet on WAS 8559 by adding the class to an existing web project within an ear and it's working as expected, ie, the timer fires every 10 seconds. What module type does your class go into? Were there any errors when you deployed or started the application? Any FFDC's? – F Rowe Jan 13 '18 at 16:46
  • I also tested your snippet on the WAS 8.5 GA release (since your post said 8.5) and it worked as expected. – F Rowe Jan 14 '18 at 15:56
  • Thank you for the comments. My WAS is 8.5.5.10. I can see the bean registered in the logs. I also checked the ffdc logs, and nothing is there. – Matei Florescu Jan 15 '18 at 09:10
  • Also my application is an ear file created with Maven. It also has some message driven beans, which are working fine. – Matei Florescu Jan 15 '18 at 09:22
  • Did you select the 'metadata-complete attribute' option during deployment? This option converts the annotations into ejb-jar.xml and then sets the metadata-complete attribute to true. Annotations will then not be scanned at runtime, but if the @Schedule annotation was not properly converted, then it will appear to be ignored. I would recommend deploying without this option to see if the problem goes away. – Tracy Feb 01 '18 at 22:47

0 Answers0