Home Java javaTutorial Example tutorial for configuring web.xml

Example tutorial for configuring web.xml

Jul 19, 2017 pm 01:39 PM
quartz web.xml perform tasks

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>
Copy after login

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();
        }
    }

}
Copy after login

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();  
     }  
}
Copy after login

Job is your own business processing

  job   execute(JobExecutionContext arg0) ==  SimpleDateFormat("yyyy-MM-dd HH:mm:ss""Time:"+"Hello"
Copy after login

三, web.xml listening:

com.thinkgem.jeesite.modules.sys.listener.TimingTaskSchedule

<listener>
<listener-class>com.thinkgem.jeesite.modules.sys.listener.TimingTaskSchedule
</listener-class>
</listener>
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Quartz to implement scheduled tasks in Java? How to use Quartz to implement scheduled tasks in Java? May 08, 2023 am 10:46 AM

Every time the Scheduler is executed, a new Job instance will be created based on the JobDetail, so that the problem of concurrent access can be avoided (the instance of jobDetail is also new). Quzrtz scheduled tasks are executed concurrently by default and will not wait for the last task to be executed. As long as It will be executed when the interval is up. If the scheduled task is executed for too long, it will occupy resources for a long time, causing other tasks to block. @DisallowConcurrentExecution: On the job class, it is prohibited to execute multiple instances of the same job definition (defined by JobDetail) concurrently. Scheduler: can be understood as a work container or workplace for scheduled tasks. All scheduled tasks

Detailed explanation of quartz configuration file Detailed explanation of quartz configuration file Jun 20, 2023 pm 04:11 PM

Quartz is an excellent Java open source scheduling framework. This article will introduce readers to the Quartz configuration file in detail and share some configuration best practices.

web.xml What is the method for SpringBoot to package executable Jar to run SpringMVC? web.xml What is the method for SpringBoot to package executable Jar to run SpringMVC? May 17, 2023 pm 09:37 PM

Deploy to the webapps directory to start. The Spring version used in this article is Spring 6, the Spring Boot version is 3, and the JDK is 17. It may be slightly different from before, but the overall process is not too different. If the deployed application is started under the tomcatwebapps directory, you need to configure the web.xml file in the project. The web.xml file configures the Spring application context contextConfigLocation/WEB-INF/spring/application-context.xmlorg.springframework.web.context.ContextLoad.

How to use Quartz to implement Java high-availability scheduled tasks? How to use Quartz to implement Java high-availability scheduled tasks? May 07, 2023 pm 12:55 PM

Guide to using scheduled tasks. If you want to do scheduled tasks, have high availability requirements, or just want to get started quickly and get started easily, then you are right to choose it. The scheduled task module further encapsulates the Quartz framework and makes it simpler to use. 1. Introduce the dependency xin.altitude.cmsucode-cms-quartz1.5.4.12 and quickly start implementing the org.quartz.Job interface; use the annotation CronExp to add the scheduling strategy of the task; use the annotation Component to inject the task into the container. Start the project, and the scheduled tasks will be monitored and run. @Component@DisallowConcurrentExecution

Servlet Container Revealed: A Deeper Understanding of the Servlet Runtime Environment Servlet Container Revealed: A Deeper Understanding of the Servlet Runtime Environment Feb 19, 2024 pm 01:00 PM

The Servlet container is an application that provides the Servlet running environment. It is responsible for managing the life cycle of the Servlet and providing necessary WEB services, such as security, transactions, etc. There are many types of Servlet containers, the most common of which are Tomcat and Jetty. The main functions of the Servlet container are life cycle management: The Servlet container is responsible for managing the life cycle of the Servlet, including startup, initialization, service and destruction. Web services: The Servlet container provides web services, such as security, transactions, etc. Resource management: Servlet container manages resources, such as Servlet, jsP, html pages, etc. Class loading: The Servlet container is responsible for adding

How to use quartz to implement scheduled tasks in Java How to use quartz to implement scheduled tasks in Java Apr 19, 2023 pm 11:49 PM

Configuration file sue.spring.quartz.cron=*/5****?pomorg.springframework.bootspring-boot-starter-quartz scheduled tasks and triggers packagecom.luke.demo.schedule;importorg.quartz.*;importorg. springframework.beans.factory.annotation.Value;importorg.springframework.context.annotation.Bea

Learn about Quartz caching technology Learn about Quartz caching technology Jun 20, 2023 am 09:51 AM

With the rapid development of Internet technology, data processing speed has become the key to competition among various industries and companies. In this process, caching technology has become an important means to improve data processing speed. Quartz caching technology, as an efficient caching technology, has been adopted by more and more enterprises. This article will introduce Quartz caching technology in detail, as well as its usage, advantages and disadvantages. 1. What is Quartz caching technology? Quartz caching technology is a memory-based caching technology that can

Using Quartz for scheduled task processing in Java API development Using Quartz for scheduled task processing in Java API development Jun 17, 2023 pm 11:58 PM

With the increasing number of Internet applications, the processing of background tasks has become more and more important. In development, we often need to process scheduled tasks, such as backing up data regularly in the early morning every day, sending emails regularly, etc. In Java development, using the Quartz library can help us implement such scheduled task processing. Quartz is an open source Java scheduled task framework that provides a simple API to implement scheduled tasks. Quartz's scheduled tasks can be based on the specified time

See all articles