Announcement Announcement Module
Collapse
No announcement yet.
Restarting scheduler on shutdown. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Restarting scheduler on shutdown.

    Hi,

    Can anyone help on this issue i have. I'm not sure whether this was the right place to post this message.

    I have this Spring - Quartz scheduler setup:

    PHP Code:
        <!-- Defines the Chat Scheduler Job Bean that will be executedThe bean is named in the jobClass property. -->
        <
    bean name="chatJob" class="org.springframework.scheduling.quartz.JobDetailBean">
          <
    property name="jobClass" value="dk.telmore.app.scheduler.ChatNotifierJob" />
        </
    bean>

        <
    bean id="chatTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
          <
    property name="jobDetail" ref="chatJob" />
          <!--
    run every 15 minbetween 07:00 21:00-->
          <
    property name="cronExpression" value="0 0/15 7-21 * * ? *" />
        </
    bean>

        <!-- 
    list of Triggers to be scheduled and executed by Quartz -->
        <
    bean name="scheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
          <
    property name="triggers">
            <list>
              <
    ref bean="chatTrigger" />
            </list>
          </
    property>
          <
    property name="applicationContextSchedulerContextKey">
            <
    value>applicationContext</value>
          </
    property>
        </
    bean

    Now i have a Struts action i wan't to restart the scheduler from, on shutdown.

    I know you can't start the same scheduler instance on shutdown, but how can i "restart" a new scheduler instance ?

    This is a section of my Struts 2 action:
    PHP Code:
    public class AppInfoAdminAction extends BaseAction implements Preparable {

        private static final 
    long serialVersionUID 2776558938719115191L;

        private 
    StdScheduler scheduler;
        private 
    boolean startScheduler;

        public 
    String execute() throws Exception {
            if (
    log.isDebugEnabled()) {
                
    log.debug("execute()");
            }
            
            
    user getUser();

            
    listJobtypes jobtypeService.getJobtypes();

            if (
    scheduler == null || scheduler.isShutdown()) {
                
    startScheduler true;
            }
           }

        public 
    String startscheduler() throws Exception {
            if (
    log.isDebugEnabled()) {
                
    log.debug("startscheduler()");
            }
            
            
    scheduler.start();

            return 
    SUCCESS;
        }


        public 
    boolean getStartScheduler() {
            return 
    startScheduler;
        }

        public 
    void setScheduler(StdScheduler scheduler) {
            
    this.scheduler scheduler;
        } 
    Notice here that the scheduler is injected by Spring.

    Also notice that on scheduler shutdown, the startscheduler method as it is now, will fail with an exception that the scheduler can not be started on shutdown.

    But if that's not an option, how can you start scheduler then ? Any ideas ?

    Best Regards
    Cemil
Working...
X