实际工程Quartz与Spring设计与实现一体化的热部署
1.需求说明
如今有这样一个需求:我们不知道管理员想设定过多厂时间运行主任务,须要在配置文件定义。在配置好后须要马上运行。实现热部署。
2.设计
3.实现
private static long curModifiedTime;
static {
try {
curModifiedTime = new File(filePath).lastModified();
System.out.println("当前文件改动时间为 " +curModifiedTime);
} catch (Exception e) {
e.printStackTrace();
} }
此时获取到文件本来的时间
public static boolean isModifiedValue()
{
boolean flag = false;
long lastModifiedTime = new File(filePath).lastModified();
if(lastModifiedTime > curModifiedTime) {
curModifiedTime= lastModifiedTime;
flag = true;
}
return flag;
}
读取文件最后改动地址。若大于初始时间。则将最后改动时间赋给初始时间
public boolean reSetTaskSchedulerzIntervalTime(){
boolean flag = false;
//监听到配置文件改动
if(PropertiesUtil.isModifiedValue()) {
long time = 0L;
try {
time = Integer.parseInt(PropertiesUtil.readValue(TaskSchedulerzIntervalTime));
simpleTrigger.setRepeatInterval(time);
Scheduler scheduler = quartzScheduler.getScheduler();
String jobName = simpleTrigger.getName();
String group = simpleTrigger.getGroup();
try {
scheduler.pauseJob(jobName, group);
scheduler.unscheduleJob(jobName,group);
scheduler.scheduleJob(simpleTrigger);
scheduler.resumeJob(jobName, group);
flag = true;
} catch (SchedulerException e1) {
e1.printStackTrace();
}
} catch (NumberFormatException e) {
System.out.println("定时任务非数字!
");
e.printStackTrace();
}
}
return flag;
}
当中,quartzScheduler和simpleTrigger是注入进去的,在Spring中整合Quartz时已经定义好,配置文件例如以下
<bean name="quartzScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref bean="simpleTrigger" />
</list>
</property>
<property name="configLocation" value="classpath:quartz.properties" />
</bean>
<bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
<property name="jobDetail">
<ref bean="jobDetail" />
</property>
<property name="startDelay">
<value>0</value>
</property>
<property name="repeatInterval" value="${taskSchedulerzIntervalTime}" />
</bean> <bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="taskScheduler" />
<property name="targetMethod" value="run" />
</bean>
之前的调度时间是在里面写死的。如今是通过配置文件来读取。例如以下
<context:property-placeholder location="classpath:config.properties,classpath:jdbc.properties" />
測试例如以下
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFja2Uy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
实际工程Quartz与Spring设计与实现一体化的热部署的更多相关文章
- spring boot (三): 热部署
介绍了Spring boot实现热部署的两种方式,这两种方法分别是使用 Spring Loaded和使用spring-boot-devtools进行热部署. 热部署是什么 大家都知道在项目开发过程中, ...
- spring boot 启动报错(spring-boot-devtools热部署后):The elements [spring.resources.cache-period] were left unbound. Update your application's configuration
详细错误代码: *************************** APPLICATION FAILED TO START *************************** Descript ...
- Spring Boot 要点--启动类和热部署
spring boot需要一个启动类 比如 package com.tianmaying; import org.springframework.boot.SpringApplication; imp ...
- Spring Boot在开发时实现热部署(开发时修改文件保存后自动重启应用)(spring-boot-devtools)
热部署是什么 大家都知道在项目开发过程中,常常会改动页面数据或者修改数据结构,为了显示改动效果,往往需要重启应用查看改变效果,其实就是重新编译生成了新的Class文件,这个文件里记录着和代码等对应的各 ...
- spring boot+ Intellj idea devtools 设置热部署
POM文件 <!--添加依赖--> <dependency> <groupId>org.springframework.boot</groupId> & ...
- 使用eclipse,对spring boot 进行springloader或者devtool热部署失败处理方法
确定配置进行依赖和配置没有错误后. 调整spring boot 的版本,因为新版本对老版本的spring boot 不能使用. 改为: <groupId>org.springframewo ...
- 使用Spring Loader或者Jrebel实现java 热部署
.其实JRebel和Spring-Loaded就是一个开发环境下的利器,skip build and redeploy process,大大提升了工作效率!而非生产环境的利器...因为线上reload ...
- Spring Boot学习笔记(三)实现热部署
pom文件中添加如下依赖即可 <dependency> <groupId>org.springframework.boot</groupId> <artifa ...
- spring boot 在idea中实现热部署
1)在pom中直接引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifac ...
随机推荐
- 3.十分钟读懂——App开发规范的业务流程
转自:http://www.itdaan.com/blog/2017/12/08/6bc06b3387a8d1238504355a6a1c6743.html 一.主要流程 二.产品立项 工作概述: ...
- Redis原理(一)
基础和应用 1.Redis是远程调用技术的首字母缩写. 2.Redis可以用来做什么? Redis可以用来做缓存. 分布式锁 3.Redis的应用举例 记录帖子的点赞数.评论数和点击数.(使用HASH ...
- ASP.Net中页面传值的几种方式
开篇概述 对于任何一个初学者来说,页面之间传值可谓是必经之路,却又是他们的难点.其实,对大部分高手来说,未必不是难点. 回想2016年面试的将近300人中,有实习生,有应届毕业生,有1-3年经验的,有 ...
- ECMALL功能拓扑图以及模式分析
ECMALL VS 常规的B2C产品(以ECSHOP做对比)的区别: 1.支持多用户在同一个域名下开店. 2.开店的卖家各自结算,直接收钱.平台只是提供了一个类似传统行业的摊位.平台不过手金钱 3 ...
- [Angular] Update FormArray with patchValue
Currently, patchValue doesn't support update FormArray. The workarround is you need to empty the for ...
- 关于pcb铺铜
- 【例题 6-15 UVA - 10129】Play on Words
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 拓扑大水题 [代码] #include <bits/stdc++.h> using namespace std; con ...
- 12、USB设备驱动程序
linux-3.4.2\driver\hid\usbhid\usbmouse.c 内核只带USB驱动程序 (hub和usb是两个不同的设备,hub在内核上电的过程中在usb_hub_init函数中调用 ...
- [AngualrJS NG-redux] Map State and Dispatchers to Redux
In this lesson, we are going to learn how to map our Angular component directly to our application s ...
- [CSS] Reduce Ambiguity in Class Names using a Naming Convention
A solid naming convention makes it less likely to run into naming conflicts and helps establish a se ...