Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fire/schedule an event after 12 hours in java

We are developing travel application for booking flight, bus tickets etc. For the flight tickets initially PNR (Passenger Name Record) will be generated, through that PNR confirmation of ticket will be done.

The problem is, if ticket is not confirmed with in 12 hours after generating the PNR, the PNR has to be canceled. If not, we will face penalty from Air GDS provider.

Up to now we have written Cron Schedulers which does this thing for every 15 minutes. We have problems by doing like this, and faced penalty also. I can't run the schedulers every minute.

How can I cancel the PNR, after generating 12 hours if not booked.

like image 747
Daya Avatar asked Dec 20 '25 11:12

Daya


2 Answers

Since this is tagged Java I recommend you to look into one of the following

  • The java.util.Timer API
  • The Quartz library.

These are the standard solutions to scheduling tasks that are to be executed in the future.

like image 60
aioobe Avatar answered Dec 22 '25 23:12

aioobe


Ontop of aioobe suggestions, I'd also have a look at the ScheduledExecutorService and Cancelling scheduled executor because I'm pretty sure that would be the next question ;)

like image 29
MadProgrammer Avatar answered Dec 23 '25 01:12

MadProgrammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!