0

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

  • You should post your edit as an answer instead... Then mark the answer once the (own-answer-)timer is done. – TT. Dec 13 '19 at 14:46
  • See this article for more details: [Can I answer my own question?](https://stackoverflow.com/help/self-answer) – TT. Dec 13 '19 at 16:09

0 Answers0