EJB timer not executed on Postgres due to timestamp comparison in JBoss EAP 7
Environment
- Red Hat Enterprise Application Platform (EAP)
- 7.3 Update 5
Issue
- EJB timer not executed on Postgres due to timestamp comparison
Resolution
The issue is fixed in EAP 7.4 GA and in EAP 7.3 Update 6+ , but existing timers in the database should be updated or removed and recreated, see more information below.
When updating to EAP 7.3 Update 6 or later if using PostgreSQL database for the EJB Timer persistence. The EJB Timer service will truncate milliseconds part of a timer's timestamp. Some existing persistent timers in timer table may already contain milliseconds in timestamp columns such as NEXT_DATE column. So to ensure these existing timers work correctly with updated EAP, users will need to perform the following one-time manual update to the affected applications.
-
Back up JBOSS_EJB_TIMER database table
-
Check NEXT_DATE columns and see if any timestamp value contains milliseconds. For example, "2021-12-17 15:08:40.971" contains milliseconds, and should be updated to the corresponding value without milliseconds: "2021-12-17 15:08:40"
-
Update all NEXT_DATE column values that contains milliseconds to the corresponding value without milliseconds.
If there are existing timers NEXT_DATE column containing milliseconds, these timers will not be run and will stay in the timer table for ever.
SQL example if table name is jboss_ebj_timer:
UPDATE jboss_ejb_timer
SET initial_date=DATE_TRUNC('seconds', initial_date), next_date=DATE_TRUNC('seconds', next_date), previous_run=DATE_TRUNC('seconds', previous_run);
Root Cause
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.