Quartz如何从Jsp停止/暂停/启动/中断调度程序,即单击特定按钮

时间:2014-06-13 05:20:38

标签: java jsp timer quartz-scheduler scheduler

请任何人转发相关的示例代码。因为我尝试了很多,并在互联网上没有有用的信息或我可以找到与之相关的链接。

先谢谢

1 个答案:

答案 0 :(得分:0)

这可能是一种解决方法。但它有效!

  1. 在您的日程安排程序中,每隔1分钟(或您选择的间隔)运行一个默认线程,以便对文件或数据库执行任何更改。
  2. 如果调度程序在数据库中找到条目,则应刷新调度程序。
  3. 在您的JSP中,单击按钮,在数据库中创建相关条目。
  4. 在ping数据库时,如果调度程序找到一个条目,那么它将执行必要的操作。

    代码段

    // Default constructor.
    public Scheduler()throws SchedulerException, Exception
    {
    
            try 
            {
    
                SchedulerFactory sf = new StdSchedulerFactory();
                sche = sf.getScheduler();
                sche.start();
    
                if(sche.isShutdown())
                {
                    SendAlerts.sendMsgToGroup("Scheduler Failed To Start at "+sdtf3.format(new Date())+" hrs.",defaultMsgGroup);
                    logger.fatal("Scheduler Failed To Start At = " + sdtf1.format(new Date()) );
                }
                else
                {
                            SendAlerts.sendMsgToGroup("Scheduler started at "+sdtf3.format(new Date())+" hrs.",SchStartAlertGroup);
                            logger.fatal("Scheduler Started At = " + sdtf1.format(new Date()) );
                }
                sysdate =   new Date();
                readFromDBAndConfigureSchedules();
                while (true)
                {
                    if(sche.isShutdown())
                    {
                            SendAlerts.sendMsgToGroup("Scheduler Failed To Start at "+sdtf3.format(new Date())+" hrs.",defaultMsgGroup);
                            logger.fatal("Scheduler Failed To Start At = " + sdtf1.format(new Date()) );
                    }
                    else
                    {
                            logger.info("Scheduler is Running. Table Last Pinged at :  "+sdtf1.format(sysdate));
                    }
    
                    /*
                    -----------------
                    IN THE CHECK DB TABLE METHOD, HANDLE REQUESTS FOR STOP, PAUSE, RE-SCHEDULE ETC 
                    ------------------
                    */
                    SchRunJob.checkDBTable();
    
                    // Loop will repeat every 1 hour = 60 minutes * 60 seconds = 3600 seconds
                    Thread.sleep (3600 * 1000);
    
                } // End of while Start Flag is Y
    
            } // End of try block
            catch (Exception e) 
            {
                SendAlerts.sendMsgToGroup( "Fatal Exception Caught.Scheduler Shut Down at " + sdtf1.format(new Date()),defaultMsgGroup);
                logger.fatal("Fatal Exception Caught.Scheduler Shut Down at " + sdtf1.format(new Date()));
                e.printStackTrace();
                System.exit(0);
            }
    } // End of default constructor**