Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz Scheduler not stopping after shutdown

I'm using the currently latest quartz 1.8.3 on jboss 4.0.5. The quartz jobs are persistent and saved into a local database. When I call the shutdown or standby method on the executing quartz scheduler object jobs still continue to execute by the scheduler, only that the jobs state is empty and the execution fails.

I would expect (at least according to quartz API documentation) that when I shutdown or make the scheduler standby, that jobs previously scheduled into the database will not be executed.

If calling shutdown or standby on the scheduler is not the method to achieve that, what is?

The jobs are not just finishing the execution but planned jobs continue to be triggered.

Here is additional info as asked:

public class QuartzNotificationsSchedulerBean implements NotificationsScheduler, ServletContextAware {
...
public String scheduleNotification(Notification notification) {

        // Schedule the job with the trigger
        try {
            // Define job instance  

                String      groupName   = this.createNotificationGroupName(notification);
                String      triggerName = this.createNoficationTriggerName(notification);
                String      jobName     = this.createNoficationJobName(notification);
                JobDetail   job         = new JobDetail(jobName, groupName , ScheduledNotificationJob.class);

                JobDataMap jobDataMap = new JobDataMap();
                jobDataMap.putAll(notification.getContext());     
                job.setJobDataMap(jobDataMap);

                Calendar notificationTime = notification.getTime();    

                Trigger trigger = new SimpleTrigger(triggerName, groupName , notificationTime.getTime());

                scheduler.scheduleJob(job, trigger);        

                return trigger.getName();           
        } catch (SchedulerException e) {
            throw new NotificationScheduleException(e, notification);
        }

        return null;
    }

public void setServletContext(ServletContext servletContext) {      
        this.sf = (SchedulerFactory) servletContext.getAttribute(QuartzInitializerListener.QUARTZ_FACTORY_KEY);

        try {
            scheduler =  sf.getScheduler();
            if(scheduler.isStarted() == false) {
                scheduler.start();
            }

        } catch (SchedulerException e) {        
            logger.error("Failed to load Quartz scheduler ", e);        
        }
    }
}

The following is a copy of the quartz configuration properties:

#============================================================================
# Configure Main Scheduler Properties  
#============================================================================

org.quartz.scheduler.instanceName = scheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.wrapJobExecutionInUserTransaction = true

#============================================================================
# Configure ThreadPool  
#============================================================================

org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 45
org.quartz.threadPool.threadPriority = 5

#============================================================================
# Configure JobStore  
#============================================================================

org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
#org.quartz.jobStore.useProperties = false
org.quartz.jobStore.dataSource = FOR_QUARTZ
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 20000


#============================================================================
# Configure Datasources  
#============================================================================

org.quartz.dataSource.FOR_QUARTZ.jndiURL = java:jdbc/live-quartz

Here is a snippet from the web.xml where the quartz is initialized:

 <!--  START NOTIFICATION SERVICE -->
    <context-param>
        <param-name>config-file</param-name>
        <param-value>wm_quartz.properties</param-value>
    </context-param>
    <context-param>
        <param-name>shutdown-on-unload</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>start-scheduler-on-load</param-name>
        <param-value>true</param-value>
    </context-param>    

    <listener>
        <listener-class>org.quartz.ee.servlet.QuartzInitializerListener</listener-class>
    </listener> 

Thanks

like image 387
Yaniv Cohen Avatar asked Aug 06 '10 07:08

Yaniv Cohen


People also ask

How do you stop a job in quartz scheduler?

scheduler. deleteJob(jobKey(<JobKey>, <JobGroup>)); This method will only interrupt/stop the job uniquely identified by the Job Key and Group within the scheduler which may have many other jobs running. scheduler.

Why we should not use Quartz scheduler?

It has no built-in UI for configuration or monitoring, no useful and reasonably searchable logging or historical review, no support for multiple execution nodes, no administration interface, no alerts or notifications, not to mention buggy recovery mechanisms for failed jobs and missed jobs.

How does Quartz Scheduler work internally?

Quartz scheduler allows an enterprise to schedule a job at a specified date and time. It allows us to perform the operations to schedule or unschedule the jobs. It provides operations to start or stop or pause the scheduler. It also provides reminder services.


2 Answers

If there are any jobs executing when you call shutdown, whether to interrupt those jobs or not depends on the property org.quartz.scheduler.interruptJobsOnShutdown.

See http://jira.terracotta.org/jira/browse/QTZ-41?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel . I am unable to find more documentation on this.

The other property is org.quartz.scheduler.makeSchedulerThreadDaemon=true, which will shutdown quartz scheduler as soon as your calling thread shuts down. I do not know what happens to the state of the jobs.

As mentioned in the comments, post some code and configuration to get clear answer.

like image 160
Adisesha Avatar answered Oct 01 '22 20:10

Adisesha


Please try to apply with these configuration when init scheduler

org.quartz.threadPool.makeThreadsDaemons=true
org.quartz.scheduler.makeSchedulerThreadDaemon=true
org.quartz.scheduler.interruptJobsOnShutdown=true
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = true

You can refer to this link for more detail: https://www.techpaste.com/2016/03/quartz-scheduler-shutdown/

like image 20
Đức Cường Nguyễn Avatar answered Oct 01 '22 20:10

Đức Cường Nguyễn