当前位置:网站首页>Quartz2.2 simple scheduling job
Quartz2.2 simple scheduling job
2022-07-23 11:42:00 【Youth without fame】
1、 The required jar file

2、web.xml To configure
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>config-file</param-name>
<param-value>quartz.properties</param-value>
</init-param>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>wait-on-shutdown</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
3、Job Implementation class
import java.util.Date;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ewa.analyzer.luenceapi.CreateIndexImpl;
import com.ewa.bean.WorksBean;
import com.ewa.bean.dao.WorksDAO;
public class _CCJob implements Job {
private static Logger _log = LoggerFactory.getLogger(CreateIndexJob.class);
private UserDao ud = null;
public _CCJob() {
ud = new UserDAO();
}
public void execute(JobExecutionContext context) {
final Lock lock = new ReentrantLock();
new Thread() {
public void run() {
lock.lock();
try {
_log.info("execute quartz job " + new Date());
System.out.println("execute quartz job " + new Date());
List<User> userList = ud.getAllUsers();
new CreateUserImpl<User>().createIndex(userList,
User.class);
_log.info("job executing finish");
System.out.println("job executing finish");
} catch (Exception e) {
_log.info("execute job errors");
System.out.println("execute job errors");
if (e.getMessage() != null) {
_log.info("errors details : " + e.getMessage());
System.out.println("errors details : " + e.getMessage());
}
} finally {
lock.unlock();
}
}
}.start();
}
}
4、
source Under the table of contents quartz.properties Definition
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = QuartzScheduler
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 5
#============================================================================
# Configure xml Plugins
#============================================================================
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz_jobs.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 30000
org.quartz.plugin.jobInitializer.wrapInUserTransaction = false
5、source Under the table of contents quartz_jobs.xml Definition
<?xml version='1.0' encoding='utf-8'?>
<job-scheduling-data
xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
version="1.8">
<schedule>
<job>
<name>c_CCJob</name>
<group>firefox</group>
<description>The job description</description>
<job-class>_CCJob</job-class>
</job>
<trigger>
<cron>
<name>my-trigger</name>
<group>firefox</group>
<job-name>c_CCJob</job-name>
<job-group>firefox</job-group>
<!-- trigger every night at 4:30 am -->
<cron-expression>0 0 0 * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
边栏推荐
- MySQL之账号管理&&四大引擎&&建库建表
- MySQL account management & four engines & database and table building
- NFT digital collection platform development and construction, source code development digital collection
- Sqli lab pass 17-22 notes
- NFT数字藏品系统开发:深圳晚报《美好时光遨游记》数字藏品上线秒磬
- [doris] configure and basically use the contents system (continue to add content when you have time)
- Data warehouse 4.0 notes - user behavior data collection III
- Security problems of FileInfo in PHP file upload
- NFT trading platform digital collection system | development and customization
- Upload lab level 1-4
猜你喜欢

Vite x sigma creates designer specific I18N plug-ins

数仓4.0笔记——数仓建模

phxpaxos安装编译流程

数仓4.0笔记——数仓环境搭建—— Yarn配置

数字藏品系统开发/数字藏品方案介绍

NFT数字藏品开发/DAPP开发

sqli-lab第17~22关通关随笔记

The 6th "Blue Hat Cup" National College Students' Cyber Security Skills Competition - preliminary writeup

Genesis曾向三箭资本提供23.6亿美元的贷款

Development of digital collection system: Baidu AI pays tribute to Air China
随机推荐
Preliminary study on DC-1 shooting range
notepad++背景颜色调整选项中文释义
自定义MVC(下)
Compilation principle - detailed explanation of syntax analysis
Web Component-自定义元素的生命周期
Pywinauto+ an application (learn to lesson 9) -- blocked
印尼央行行长称该国正在积极探索加密资产
数字藏品开发/数字藏品系统开发解决方案
mysql免密登录设置
Dynamically set the theme color of the card
window运行gradle build -- --stacktrace出现找不到文件framework-4.3.0.BUILD-SNAPSHOT-schema.zip异常
NFT数字藏品系统开发:徐悲鸿美术馆通过数字藏品平台亮相
Data warehouse 4.0 notes - Data Warehouse Modeling
NFT数字藏品系统开发:深圳晚报《美好时光遨游记》数字藏品上线秒磬
kubesphere HA install (二)
编译原理-语法分析详解
Php+ code cloud code hook automatically updates online code
渗透测试基础
Web component - the lifecycle of a custom element
Fed Brad: last week's employment report showed that the U.S. economy is robust and can withstand higher interest rates