Self-developed and implemented Quartz Web management, and developed and implemented quartzweb

Source: Internet
Author: User

Self-developed and implemented Quartz Web management, and developed and implemented quartzweb

The QuartzWeb management materials that can be found on the Internet are the Quartz WebApp stuff written by a foreign user, with comprehensive functions. However, as your own application, it does not actually use so many functions. Generally, we only need to define a job and specify a Cron expression to complete the work. The attached job can be paused and restarted, basically, the application can be satisfied. In addition, the online things are a little complicated and cannot be integrated into your own projects, whether in style or style.

For this reason, it is also to learn a Quartz (which has not been used before ). I want to build a simple Quartz Web management tool. Including adding a task (the added task can only be a task that implements the Quartz Job Interface), pausing, starting, and deleting the task. Basically, all of these can meet the needs of daily applications.

List page:


Add task page


There is no interface for pausing or restarting. In fact, when the requirements are not complex, the above functions can meet the application requirements. If you want to modify the time of a task, delete and recreate it.

To implement these functions, there are only two simple JSP, two Servlets, and two helper classes. It is easy to modify when integrating your own projects.

This feature requires the use of the JobStoreTX method of Quartz local storage, rather than RAMJobStore.

When integrating with your own project, you may need to modify the following points.

1. TaskListServlet uses the data source of the project and needs to be modified according to the actual situation. TaskOprateServlet is mainly used to complete related operations and does not involve databases. Quartz APIs are called. If necessary, you can migrate the content in the Two JSPs to the Action or Controller of your project.

2. Modify the JS file path introduced in the related JSP. You may also need to modify the path URL for accessing background resources.

3. Because the Job information of Quartz is stored in the database, we need to use the JobStoreTX of Quartz. All the configuration items are in quartz. properties. The content of my file is as follows:

#===============================================================     #Configure Main Scheduler Properties     #===============================================================       org.quartz.scheduler.instanceName=QuartzSchedulerorg.quartz.scheduler.instanceId=AUTO #===============================================================     #Configure ThreadPool     #===============================================================       org.quartz.threadPool.threadCount =5org.quartz.threadPool.threadPriority =5org.quartz.threadPool.class=org.quartz.simpl.SimpleThreadPool #===============================================================     #Configure JobStore     #===============================================================       org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTXorg.quartz.jobStore.driverDelegateClass =org.quartz.impl.jdbcjobstore.oracle.OracleDelegateorg.quartz.jobStore.tablePrefix = QRTZ_#============================================================================# Configure Datasources  #============================================================================org.quartz.jobStore.dataSource = myDSorg.quartz.dataSource.myDS.driver =oracle.jdbc.driver.OracleDriverorg.quartz.dataSource.myDS.URL = jdbc:oracle:thin:@localhost:1521:orclorg.quartz.dataSource.myDS.user = loushang_testorg.quartz.dataSource.myDS.password = loushang_testorg.quartz.dataSource.myDS.maxConnections = 5#===============================================================     #Configure Plugins  only config JobInitializationPlugin but read quartz_jobs.xml file#===============================================================       org.quartz.plugin.jobInitializer.class=org.quartz.plugins.xml.JobInitializationPlugin      org.quartz.plugin.jobInitializer.overWriteExistingJobs=trueorg.quartz.plugin.jobInitializer.failOnFileNotFound=trueorg.quartz.plugin.jobInitializer.validating=false

4. In the JobTools class, QUARTZ_INSTANCE_NAME is configured with the instanceName value in the quartz. properties configuration file. In fact, configuration is not adequate, but it is recommended to configure.

This is basically the case. In short, it is quite simple. In this application, all jobs and triggers must be in the same DEFAULT group.

The background code is basically simple. The code for adding a task is as follows:

String jobName = req.getParameter("jobName");String jobGroup = req.getParameter("jobGroup");String triggerName = req.getParameter("triggerName");String triggerGroup = req.getParameter("triggerGroup");String JobClassName = req.getParameter("JobClassName");String jobDescription = req.getParameter("jobDescription");String cronExpression = req.getParameter("cronExpression");String startTime = req.getParameter("startTime");String endTime = req.getParameter("endTime");CronTrigger ct = new CronTrigger(triggerName.trim(),triggerGroup,cronExpression);if(startTime!=null && !"".equals(startTime)){Date date = JobTools.paraseToDate(startTime);ct.setStartTime(date);}if(endTime!=null && !"".equals(endTime)){Date date = JobTools.paraseToDate(endTime);ct.setEndTime(date);}Class clz = Class.forName(JobClassName.trim());JobDetail jd = new JobDetail(jobName.trim(),jobGroup,clz);jd.setDescription(jobDescription.trim());Scheduler scheduler = JobTools.getScheduler();scheduler.scheduleJob(jd, ct);

You can download the case code from the following locations:

Http://download.csdn.net/detail/srar_hanshui/8867063

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.