How to unload the scheduler when Play is stopped/reloaded
Closed this issue · 1 comments
Using the scheduler in Play for Scala, I initiate the scheduler on startup like so:
val scheduler = QuartzSchedulerExtension(system) val d = scheduler.schedule("dailyproc", mainEtl, "abc", None)
Problem is that I load a table using Hibernate in the scheduler task, and when Play is reloaded due to code change, I get an error saying that classes "cannot be cast" where the class is the same. This happens because the classloaders are different.
One solution is to unload the scheduler when Play is reloaded, how can this be achieved? I could not find a method to unload the scheduler when Play is stopped/reloaded.
I tried with
scheduler.shutdown(true)
but it doesn't seem to unload the classes
Please see more details here
Hi @ps3331333,
This issue is really more of a Play issue than anything else, I believe, as Play causes this kind of issue with a few different libraries.
Basically, you'll want to use the ApplicationLifecycle
to manage this. You can read more about that here. Hopefully that helps.