quartz简单定时任务【可以处理完一个任务才开启下一个线程】【我】
maven jar project项目一个
pom文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-jar-quartz</artifactId>
<version>0.0.1-SNAPSHOT</version> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies> </project>
java代码:
package com.test1;
import java.text.SimpleDateFormat;
import java.util.Date; import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; @DisallowConcurrentExecution//此注解目的为一定是已经执行完一个任务才按照时间去开启下一个任务
public class MyJob implements Job { public void execute(JobExecutionContext context) throws JobExecutionException {
//打印当前的执行时间,格式为yyyy-MM-dd HH:mm:ss
// 编写具体的业务逻辑。
Date date=new Date();
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//规范格式
System.out.println("当前时间为:"+sf.format(date));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("Hello World!---线程名---: "+Thread.currentThread().getName()+"--当前对象--:"+this);
} }
package com.test1;
import java.text.SimpleDateFormat;
import java.util.Date; import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory; public class MyScheduler {
public static void main(String[] args) throws SchedulerException
{
//创建一个JobDetail实例,将该实例与MyJob Class绑定。
JobDetail jobDetail=JobBuilder.newJob(MyJob.class).withIdentity("myJob", "group1").build();
//创建一个Trigger实例,定义该Job立即执行,并且每隔3秒钟重复一次,
Trigger trigger=TriggerBuilder
.newTrigger()
.withIdentity("myTrigger","group1")
.startNow()
.withSchedule(SimpleScheduleBuilder
.simpleSchedule()
.withIntervalInSeconds(3)
.repeatForever())
.build();
SchedulerFactory sf=new StdSchedulerFactory();
Scheduler scheduler=sf.getScheduler();
scheduler.start();
Date date=new Date();
SimpleDateFormat sfd=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//规范格式
//System.out.println("当前时间为:"+sfd.format(date));
scheduler.scheduleJob(jobDetail, trigger);
}
}
quartz简单定时任务【可以处理完一个任务才开启下一个线程】【我】的更多相关文章
- @DisallowConcurrentExecution 注解的作用 【定时器执行完当前任务才开启下一个线程的方式】
转: @DisallowConcurrentExecution 注解的作用 2018年10月12日 16:42:40 fly_captain 阅读数:4317 Quartz定时任务默认都是并发执行 ...
- IntentService 串联 按顺序执行(此次任务执行完才执行下一个任务)
IntentService与Service的最大区别就是前者依次执行,执行完当前任务才执行下一个任务,后者并发执行 在IntentService里面不写onCreate方法 MainActivity: ...
- spring 默认情况下事务是惟一的 同一个方法里面第一个sql开启后 在执行完 将事务传递给下一个sql
spring 默认情况下事务是惟一的 同一个方法里面第一个sql开启后 在执行完 将事务传递给下一个sql
- 编写一个程序,开启 3 个线程,这三个线程的 ID 分别为 A、B、C,每个线程将自己的 ID 在屏幕上打印 10 遍,要求输出的结果必须按顺序显示。如:ABCABCABC…… 依次递归
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.uti ...
- JQ 获取下一个元素和获取下一个元素的[指定]子元素
<script type="text/javascript"> $(function () { $("#div1").next().addClass ...
- jquery 获取上一个兄弟元素和下一个兄弟元素
jQuery.prev(),返回上一个兄弟节点,不是所有的兄弟节点 jQuery.prevAll(),返回所有之前的兄弟节点 jQuery.next(),返回下一个兄弟节点,不是所有的兄弟节点 jQu ...
- 为什么Java中一个char能存下一个汉字
在Java中,char的长度是2字节,即16位,2的16次方是65536. 1.如果采用utf-8编码,一个汉字占3个字节,char为什么还能存下一个汉字呢? 参考:https://developer ...
- 多个input连接在一起的时候如何实现输入一个数字跳入下一个
这个是页面内容 ,我分了12格子,作为一个12位的会员卡号的输入;其实就是12个input我把他们放在了一个div里面 这样配上背景图,看着是一个大的输入框. <div id="A ...
- [shell]上一个命令执行完成,才执行下一个操作 | shell脚本中判断上一个命令是否执行成功
shell脚本中判断上一个命令是否执行成功 shell中使用符号“$?”来显示上一条命令执行的返回值,如果为0则代表执行成功,其他表示失败.结合if-else语句实现判断上一个命令是否执行成功. 场 ...
随机推荐
- Nginx code 常用状态码学习小结
最近了解下Nginx的Code状态码,在此简单总结下.一个http请求处理流程: 一个普通的http请求处理流程,如上图所示:A -> client端发起请求给nginxB -> ngin ...
- Gerrit日常维护记录
Gerrit代码审核工具是个好东西,尤其是在和Gitlab和Jenkins对接后,在代码控制方面有着无与伦比的优势. 在公司线上部署了一套Gerrit系统,在日常运维中,使用了很多gerrit命令,在 ...
- E. Binary Numbers AND Sum
链接 [http://codeforces.com/contest/1066/problem/E] 题意 给你长度分别为n,m的二进制串,当b>0时,对a,b,&运算,然后b右移一位,把 ...
- NEWBE CRALWER 产品需求文档
1.产品概述 本产品是学霸软件系统的爬虫部分,由NEWBE团队负责.主要任务是从网上爬取出相关数据后提供给C705组使用. 2.产品的发展经历 2.1 产品的发展经历 本产品从2014.10.29开始 ...
- 个人博客Week3——案例分析
一.调研,评测 我使用的bing的WINDOWS客户端,其大致分为四个模块:词典.例句.翻译.应用. (1)“词典”模块 BUG:搜索”http“词条,界面显示http的相关,但是无法再回到最初的主界 ...
- Timer定时执行
//定时器 public void timeTask(String hh,int n) {//hh="8:30:00",n=12 Timer timer = new Timer() ...
- personal project
words count program 统计文本文件的字符数,单词数和行数. 实现一个统计程序,他能正确的统计程序文件中的字符数,单词数和行数. 源码链接 https://github.com/sup ...
- spatial-temporal information extraction典型方法总结
==================================== 咳咳咳 由于科研的直接对象就是video sequence,所以,如何更好地提取spatial-temporal inform ...
- org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: c
//这个是 配置文件放错了地方 org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing ...
- Server Tomcat v7.0 Server at libra failed to start
https://stackoverflow.com/questions/13244233/server-tomcat-v7-0-server-at-localhost-failed-to-start- ...