Spring集成quartz集群配置总结
1.spring-quartz.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- expiration notice -->
<bean id="expirationNoticeService" class="org.guyezhai.demo.service.scheduler.ExpirationNoticeService"/>
<bean id="expirationNoticeDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass">
<value>org.guyezhai.modules.quartz.DXQuartzJobBean</value>
</property>
<property name="jobDataMap">
<map>
<entry key="targetObject" value="expirationNoticeService" />
<entry key="targetMethod" value="execute" />
<entry key="concurrent" value="false" />
</map>
</property>
</bean>
<bean id="expirationNoticeTriggers" class="org.guyezhai.modules.quartz.InitCronTrigger">
<constructor-arg value="expirationNoticeTriggers"/>
<property name="jobDetail" ref="expirationNoticeDetail" />
</bean> <bean id="scheduler" lazy-init="true" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="configLocation" value="classpath:quartz.properties"/>
<property name="triggers">
<list>
<ref local="expirationNoticeTriggers"/>
</list>
</property>
<property name="applicationContextSchedulerContextKey" value="applicationContext" />
</bean> </beans>
2.quartz.properties
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = DEMO
org.quartz.scheduler.instanceId = AUTO #============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount =
org.quartz.threadPool.threadPriority = #============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = false
org.quartz.jobStore.dataSource = demo
org.quartz.jobStore.tablePrefix = qrtz_
org.quartz.jobStore.misfireThreshold =
org.quartz.jobStore.dontSetAutoCommitFalse = false
org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = #============================================================================
# Configure Datasources
#============================================================================
org.quartz.dataSource.deptusercert.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.deptusercert.URL = jdbc\:mysql\://127.0.0.1\:3306/demo
org.quartz.dataSource.deptusercert.user = root
org.quartz.dataSource.deptusercert.password = sa
org.quartz.dataSource.deptusercert.maxConnections =
org.quartz.dataSource.deptusercert.validationQuery = select from dual
3.InitCronTrigger.java
package org.guyezhai.modules.quartz; import org.guyezhai.demo.dao.scheduler.SchedulerInfoDao.SchedulerInfoDao;
import org.guyezhai.demo.entity.po.scheduler.SchedulerInfo.SchedulerInfo;
import org.guyezhai.modules.spring.context.SpringContextHolder;
import org.guyezhai.modules.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.CronTriggerFactoryBean; /**
* 初始化CronTrigger
*/
public class InitCronTrigger extends CronTriggerFactoryBean {
private static Logger logger = LoggerFactory.getLogger(InitCronTrigger.class); private String triggerid;
private SchedulerInfoDao schedulerInfoDao; public InitCronTrigger(String triggerid) {
super();
logger.info("------InitCronTrigger.InitCronTrigger():" + triggerid);
try {
schedulerInfoDao = SpringContextHolder.getBean(SchedulerInfoDao.class); String cronExpression = getCronExpressionFromDB(triggerid);
if (StringUtils.isNotBlank(cronExpression)) {
this.setCronExpression(cronExpression);
// logger.info("------setCronExpression:" + this.getCronExpression());
}
} catch (Exception e) {
e.printStackTrace();
} } /**
* 从数据库中获取cronExpression
*
* @param triggerid
* @return
*/
private String getCronExpressionFromDB(String triggerid) {
SchedulerInfo schedulerInfo = schedulerInfoDao.get(triggerid);
return null == schedulerInfo ? "" : schedulerInfo.getCronExpression();
} public String getTriggerid() {
return triggerid;
} public void setTriggerid(String triggerid) {
this.triggerid = triggerid;
}
}
4.DXQuartzJobBean.java
package org.guyezhai.modules.quartz; import java.lang.reflect.Method; import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean; /**
* 解决quartz集群class序列化的问题
*/
public class DXQuartzJobBean extends QuartzJobBean {
private static Logger logger = LoggerFactory.getLogger(DXQuartzJobBean.class); private String targetMethod;
private String targetObject;
private ApplicationContext applicationContext; @Override
protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
try {
logger.warn("INFO: execute [" + targetObject + "] at once...");
Object otargetObject = applicationContext.getBean(targetObject);
Method m = null;
try {
m = otargetObject.getClass().getMethod(targetMethod, new Class[] {});
m.invoke(otargetObject, new Object[] {});
} catch (SecurityException e) {
logger.error("DXQuartzJobBean.executeInternal()", e);
} catch (NoSuchMethodException e) {
logger.error("DXQuartzJobBean.executeInternal()", e);
}
} catch (Exception e) {
// throw new JobExecutionException(e);
logger.error("DXQuartzJobBean.executeInternal()", e);
}
} public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
} public void setTargetObject(String targetObject) {
this.targetObject = targetObject;
} public void setTargetMethod(String targetMethod) {
this.targetMethod = targetMethod;
}
}
Spring集成quartz集群配置总结的更多相关文章
- Spring+quartz集群配置,Spring定时任务集群,quartz定时任务集群
Spring+quartz集群配置,Spring定时任务集群,quartz定时任务集群 >>>>>>>>>>>>>> ...
- Spring集成Redis集群(含spring集成redis代码)
代码地址如下:http://www.demodashi.com/demo/11458.html 一.准备工作 安装 Redis 集群 安装参考: http://blog.csdn.net/zk6738 ...
- Spring Cloud Eureka集群配置及注意事项(Greenwich版本)
Spring Cloud Eureka集群配置及注意事项(Greenwich版本) 一·概述 Spring Cloud Netflix Eureka 是一个提供服务注册与发现的套件.服务提供者只需要将 ...
- (4) Spring中定时任务Quartz集群配置学习
原 来配置的Quartz是通过spring配置文件生效的,发现在非集群式的服务器上运行良好,但是将工程部署到水平集群服务器上去后改定时功能不能正常运 行,没有任何错误日志,于是从jar包.JDK版本. ...
- Quartz集群配置
先看看quartz的持久化基本介绍: 引用 1 大家都清楚quartz最基本的概念就是job,在job内调用具体service完成具体功能,quartz需要把每个job存储起来,方便调度,quartz ...
- spring boot + quartz 集群
spring boot bean配置: @Configuration public class QuartzConfig { @Value("${quartz.scheduler.insta ...
- Springboot2.X集成Quartz集群
为什么要使用Quzrtz集群 在项目进行集群部署时,如果业务在执行中存在互斥关系,没有对定时任务进行统一管理,就会引起业务的多次执行,不能满足业务要求.这时就需要对任务进行管理,要保证一笔业务在所有的 ...
- spring 使用redis集群配置
上面两篇介绍了redis集群的配置合一些基本的概念,所以接下来当然是要在项目中使用咯,redis的java支持已经做的非常好了,所以我们来试着使用这些api来进行redis的操作,首先我们需要操作re ...
- 搭建高可用rabbitmq集群及spring boot实现集群配置
java spring boot配置: //具体参看了配置的源码 org.springframework.boot.autoconfigure.amqp.RabbitProperties //Rabb ...
随机推荐
- mysql-otp 驱动中设置utf8mb4
utf8mb4支持emoji表情,在mysql中设置连接字符集为utf8mb4可以直接储存emoji表情. 可以在客户端连接中设置: SET NAMES utf8mb4 查看是否起效: SHOW VA ...
- bond下改变网卡
浪潮服务器打开控制台 用ip addr查看哪个网卡是绑定的,eth2和eth4是绑定状态 用mv命令,更改网卡名称 并将每个网卡里的信息更改 reboot,重启 ip addr查看,eth6和eth8 ...
- 奇异值分解(SVD)原理详解及推导(转载)
转载请声明出处http://blog.csdn.net/zhongkejingwang/article/details/43053513 在网上看到有很多文章介绍SVD的,讲的也都不错,但是感觉还是有 ...
- PAT 甲级 1054 The Dominant Color
https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768 Behind the scenes in t ...
- larave5.6 引入自定义函数库时,报错不能重复定义
方法一:使用function_exists判断 方法二:使用命名空间 namespace test; function test(){ echo 'test/test'; } namespace te ...
- 第80天:jQuery插件使用
jQuery其他补充+ 4.1 链式编程: end()补充 * 补充五角星 评论案例 * 第一步:鼠标移入,当前五角星和前面的五角星变实体.后面的变空心五角星 * 第二步:鼠标点击的时候,为当前元素添 ...
- HDU4646_Laser Beam
题目是这样的,一个等边三角形,三边都是有镜子组成的. 现在要你从一个点射入一条光线,问你如果要求光线在三角形里面反射n次然后从入点射出来的话,入射的方向可能有多少种? 这.....其实不难.关键是要搞 ...
- Strus默认跳转方式是请求转发 地址栏不变 与javaweb的内部转发一样
Strus默认跳转方式是请求转发 地址栏不变 与javaweb的内部转发一样
- java 集合 父类的使用子类的方法时候 底层自动转型为子类的数据类型
跟继承多态不一样 继承多态需要显示转型
- Spring Batch @SpringBatchTest 注解
Spring Batch 提供了一些非常有用的工具类(例如 JobLauncherTestUtils 和 JobRepositoryTestUtils)和测试执行监听器(StepScopeTestEx ...