Quartz Scheduler Testing scenario not working

那年仲夏 提交于 2019-12-12 23:05:18

问题


I'm using quartz scheduler with my spring app. Everything works fine so far but while testing a scheduled job in future lets say a month from now, I schedule a job, and then change the system time of my linux machine to that day and 5 mins before the trigger was supposed to fire. I waited, the trigger fire time came and went by but didn't fire. The other approach i was able to test was to change the fire time in the oracle table so that we don't need to change system time. It also works when i schedule a job for the next day at 4(without need to change any date, but I waited 24 hrs for that to fire and it did). I don't understand why accelerated system time does not work with quartz. Any explanation would be helpful. thanks!

P.S: I'm using the core libraries from quartz and not spring integrated quartz libs.


回答1:


After quite some time spent on this, I enabled the logs for org.quartz and found that quartz was not initialized when the app loads. Following snippet will initialize quartz during startup:

    <servlet>
        <servlet-name>QuartzInitializer</servlet-name>
        <servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
        <init-param>
            <param-name>shutdown-on-unload</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>start-scheduler-on-load</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>config-file</param-name>
            <param-value>quartz.properties</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>


来源:https://stackoverflow.com/questions/40245113/quartz-scheduler-testing-scenario-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!