views:

266

answers:

1

Hi All,

I have a requirement in which I have to do a certain database relted activity when my Quartz will be shut down. I mean I have to wipe out a certain data from the database when I shutdown the scheduler. Is there any way I can achieve this?

While googling I came across methods to determine the present state of the scheduler. But, is there a way I can capture this scheduler shutdown event.

Thanks in Advance, Ibu

+3  A: 

Can you add a ScheduleListener and watch for calls on schedulerShutdown() ?

e.g. Implement an instance of ScheduleListener (which would probably only do something for the implementation of schedulerShutdown().

Then add it to your scheduler instance using Scheduler.addSchedulerListener(). That way your instance of SchedulerListener should get a callback when the scheduler shuts down.

This assumes the scheduler shuts down cleanly. You may have to add a Runtime shutdownHook to ask the scheduler to shutdown.

Brian Agnew
Thanks for the reply Brian, a simple example would really help me a lot to understand.
I've not done this (I confess) but I've enhanced my answer a little. Hopefully that should get you going....
Brian Agnew
Hey, gr8.. it worked.. 1 more query if you dont mind ;).. Although I am pretty sure there's no way I can do any activity in case my Scheduler does not shut down cleanly(ex: i closed the command window/ pressed ctrl+c while scheduler is still running), u think there's any such way or turnaround I can handle this?
Probaly not. But have you implemented a shutdown hook, which should get called in most cases when the JVM gets a shutdown request ?
Brian Agnew