I wrote an EJB scheduler that worked a few days ago, now it doesn't work. I tried to delete the contents of the / wildfly / standalone / data / timer-service-data directory but the scheduler does not work. This is the code of my EJB:
@Singleton
public class MyTimerService {
@Resource
private TimerService timerService;
/** The Constant logger. */
private static final Logger logger = Logger.getLogger(MyTimerService.class);
@PostConstruct
public void initialize() {
logger.info("MyTimerService initialization");
ScheduleExpression scheduleExpression = new ScheduleExpression().hour("*").minute( "*/5");
// Persistent must be set to false (since it defaults to true) because the timer is not specific to this JVM.
TimerConfig test = new TimerConfig("START TIMER", false);
timerService.createCalendarTimer(scheduleExpression, test);
}
@Timeout
public void scheduler(Timer timer) {
//my logic here ...
}
@PreDestroy
public void stop() {
logger.info("SingletonTimer is stopping: the server is either being shutdown or another node has become elected to be the singleton master.");
}
My code looks correct, maybe it's a server problem?
EDIT:
I added @Startup and now it works :)