Today on the project, you need to do a timing task. If you learn temporarily, the function of Quartz is still very convenient to use. The DEMO here is only implemented once a day. Other functions can continue to study on this basis. Haha sleeps on this. Haha sleeps. , continue tomorrow.
I have always had the idea to record, organize and share what I have learned. I have never done it. Today I will start the first article. This is a scheduled task that needs to be done on today’s project. I learned it temporarily. The function of quartz is still It is very powerful and easy to use. The demo here only implements scheduled execution once a day. Other functions can be further studied on this basis. Haha, sleep and continue tomorrow.
1. Maven dependency:
<dependency><groupid>org.quartz-scheduler</groupid><artifactid>quartz</artifactid><version>2.2.3</version> </dependency> <dependency><groupid>org.quartz-scheduler</groupid><artifactid>quartz-jobs</artifactid><version>2.2.3</version> </dependency>
2. Doem:
TimingTaskSchedule needs to implement the ServletContextListener interface to start the project after listening Class
package com.thinkgem.jeesite.modules.sys.listener;import javax.servlet.ServletContextEvent;import javax.servlet.ServletContextListener;public class TimingTaskSchedule implements ServletContextListener{// 服务器启动时执行该事件 @Overridepublic void contextInitialized(ServletContextEvent arg0) {try { QuartzLoad.run(); } catch (Exception e) { e.printStackTrace(); } }// 服务器停止时执行该事件 @Overridepublic void contextDestroyed(ServletContextEvent arg0) {try { QuartzLoad.stop(); } catch (Exception e) { e.printStackTrace(); } } }
The 0 0 0 ? * * means execution once every day at 00:00:00
represents seconds from left to right Time-sharing day-month anniversary
? Indicates that you don’t care* means you can ignore it and don’t write it every year
package com.thinkgem.jeesite.modules.sys.listener;import org.quartz.CronScheduleBuilder;import org.quartz.CronTrigger;import org.quartz.Job;import org.quartz.JobBuilder;import org.quartz.JobDetail;import org.quartz.Scheduler;import org.quartz.SchedulerFactory;import org.quartz.TriggerBuilder;import org.quartz.impl.StdSchedulerFactory;import com.thinkgem.jeesite.modules.sys.listener.job;public class QuartzLoad {private static Scheduler sched; public static void run() throws Exception { System.out.println("定时任务启动"); JobDetail jobDetail = JobBuilder.newJob((Class extends Job>) job.class) .withIdentity("myjob", "group1").build();CronTrigger trigger =(CronTrigger) TriggerBuilder.newTrigger() .withIdentity("trigger", "group1") .withSchedule(CronScheduleBuilder.cronSchedule("0 0 0 ? * *")) .build(); SchedulerFactory sfact = new StdSchedulerFactory(); Scheduler schedule = sfact.getScheduler(); schedule.start(); schedule.scheduleJob(jobDetail, trigger); }//停止 public static void stop() throws Exception{ sched.shutdown(); } }
Job is your own business processing
job execute(JobExecutionContext arg0) == SimpleDateFormat("yyyy-MM-dd HH:mm:ss""Time:"+"Hello"
三, web.xml listening:
com.thinkgem.jeesite.modules.sys.listener.TimingTaskSchedule
<listener> <listener-class>com.thinkgem.jeesite.modules.sys.listener.TimingTaskSchedule </listener-class> </listener>
The above is the detailed content of Example tutorial for configuring web.xml. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor