79223485

Date: 2024-11-25 14:47:49
Score: 0.5
Natty:
Report link

I found a way to make it work. It seems the problem was with the annotations. My EJB programmatic timer was not executing even if I changed it to a really simple case.

I used the annotation @Singleton instead of @Stateless (both can't be used) and @Startup like this:

@Singleton
@Startup
public class ExpirationWatch {

@Resource
private TimerService timerService;

@Inject
@ConfigProperty(name = "app.cronExpiredDepartures", defaultValue = "* * * * *")
private String cronExpression;


@PostConstruct
public void init() {
    ScheduleExpression schedule = new ScheduleExpression();

    String[] parts = cronExpression.split(" ");
    schedule
        .second("0")
        .minute(parts[0])
        .hour(parts[1])
        .dayOfMonth(parts[2])
        .month(parts[3])
        .dayOfWeek(parts[4]);

    timerService.createCalendarTimer(schedule, new TimerConfig("ExpirationWatchTimer", false));
}

@Timeout
@Transactional
public void checkExpiredDepartures()  {

    System.out.println("checkExpiredDepartures executed");
    
        }
    }
}
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Singleton
  • User mentioned (0): @Stateless
  • User mentioned (0): @Startup
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: User1