Sunday 21 April 2013

Java Quartz Scheduler Next Fire Time in Date Format (DD-MM-YYYY HH:MM:SS) format


QUARTZ is a powerful and advance scheduler framework, to help Java developer to schedule a job to run at a specified date and time.

Quartz used in conjunction with the Databases i,e store the jobs,trigger details and the triggering time persist in the Database as a set of relational tables.The details of when the next job will trigger is stored in the column NEXT_FIRE_TIME in the table QRTZ_TRIGGERS(remember that "QRTZ_" in the table name is a user defined prefix) as milliseconds passed from the Date (Jan 1, 1970). We come across a testing scenario where we need to know the next trigger time like may be after a month.

So to make the Next fire time or may be the previous fire time to human readable Date Format (DD-MM-YYYY HH:MM:SS)  you could you query the database with the following SQL Query.  

select Trigger_Name,to_date('1970-01-01','yyyy-mm-dd hh:mi:ss') + (&NEXT_FIRE_TIME/86400000) from QRTZ_2_TRIGGERS


"&NEXT_FIRE_TIME" is the value of the NEXT_FIRE_TIME column in milliseconds stored as long int.

86400000=(24*60*60*1000)

                         (hours*minutes*seconds*milliseconds)


2 comments: