Yantes
Yantes

Reputation: 251

What happens if I do not shutdown() quartz scheduler

What would happen if I do not call the shutdown() method on my Quartz scheduler?

I have a job that needs to be run each day at different times the day:

    Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

            JobDetail job = newJob(NotificationCronJob.class).withIdentity("notificationJob1", "notificationGroup1").build();

            CronTrigger cronTriggerSunday = newTrigger().withIdentity("notificationTrigger1", "notificationGroup1")
                    .withSchedule(cronSchedule(Config.SUNDAY_NOTIFY))
                    .forJob(job)
                    .build();
            CronTrigger cronTriggerMonday = newTrigger().withIdentity("notificationTrigger2", "notificationGroup1")
                    .withSchedule(cronSchedule(Config.MONDAY_NOTIFY))
                    .forJob(job)
                    .build();
            CronTrigger cronTriggerTuesday = newTrigger().withIdentity("notificationTrigger3", "notificationGroup1")
                    .withSchedule(cronSchedule(Config.TUESDAY_NOTIFY))
                    .forJob(job)
                    .build();
            CronTrigger cronTriggerWednesday = newTrigger().withIdentity("notificationTrigger4", "notificationGroup1")
                    .withSchedule(cronSchedule(Config.WEDENSDAY_NOTIFY))
                    .forJob(job)
                    .build();
            CronTrigger cronTriggerThursday = newTrigger().withIdentity("notificationTrigger5", "notificationGroup1")
                    .withSchedule(cronSchedule(Config.THURSDAY_NOTIFY))
                    .forJob(job)
                    .build();
            CronTrigger cronTriggerFriday = newTrigger().withIdentity("notificationTrigger6", "notificationGroup1")
                    .withSchedule(cronSchedule(Config.FRIDAY_NOTIFY))
                    .forJob(job)
                    .build();
            CronTrigger cronTriggerSaturday = newTrigger().withIdentity("notificationTrigger7", "notificationGroup1")
                    .withSchedule(cronSchedule(Config.SATURDAY_NOTIFY))
                    .forJob(job)
                    .build();

            scheduler.scheduleJob(job, cronTriggerSunday);
            scheduler.scheduleJob(cronTriggerMonday);
            scheduler.rescheduleJob(cronTriggerMonday.getKey(), cronTriggerMonday);
            scheduler.scheduleJob(cronTriggerTuesday);
            scheduler.scheduleJob(cronTriggerWednesday);
            scheduler.scheduleJob(cronTriggerThursday);
            scheduler.scheduleJob(cronTriggerFriday);
            scheduler.scheduleJob(cronTriggerSaturday);

            scheduler.start();

Each Config.DAY is a cron expression fore example 0 0 9 ? * 1 run each sunday at 9am.

Now the problem is if I shutdown the scheduler the job would never be run, so therefore I just start it and just let it run. But I am concerned with if that would result in some memory leak og threading problem of some kind, I cannot figure out if this is a well enough solution. My quartz properties are as follows:

org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX

org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.MSSQLDelegate
org.quartz.jobStore.dataSource = myDS
org.quartz.dataSource.myDS.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
org.quartz.dataSource.myDS.URL = jdbc:sqlserver://localhost;databaseName=myDB
org.quartz.dataSource.myDS.user = myUser
org.quartz.dataSource.myDS.password = myPassword
org.quartz.dataSource.myDS.maxConnections = 5
org.quartz.jobStore.tablePrefix = QRTZ_

What I need to achieve in the end is an application that runs a job at the defined times and the scheduling should be mutable without restarting the application.

Upvotes: 1

Views: 2033

Answers (1)

hiroyukik
hiroyukik

Reputation: 816

Quartz scheduler shouldn't call 'shutdown' method while your application is running. If you found any problem such as memory leak, you can issue the problem to Quartz community.

If 'shutdown' is called, Quartz scheduler is never restarted even if you call 'start' method again.

Please refer to the below URL which is Quartz documentation. http://www.quartz-scheduler.org/documentation/quartz-2.x/cookbook/ShutdownScheduler.html

Upvotes: 2

Related Questions