- 浏览: 425443 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (164)
- Lucence (1)
- Hibernate (16)
- java综合技术点 (31)
- struts (4)
- dwr (2)
- IT生活 (21)
- spring (12)
- tomcat (1)
- 数据库 (11)
- tags (0)
- 线程安全 (11)
- 设计模式 (1)
- 缓存 (4)
- WebService (5)
- Apache软件 (7)
- java定时器 (1)
- plugin开发用插件 (3)
- Web前端 (5)
- js (3)
- Android (2)
- 摘抄 (0)
- jdbc (1)
- FTP (1)
- jetty (1)
- 图表 (1)
- Exception (1)
- 问题点整理 (1)
- 备忘录 (2)
- 分布式 (0)
- hadoop (0)
- JVM (5)
- GC (1)
- 消息中间件 (0)
最新评论
-
honganlei:
个人推荐一个,虽然是第三方的,但是提供的都是官方下载地址htt ...
常用jar包下载地址 -
chengt:
java jar包下载我一般用以下两个网站都可以http:// ...
常用jar包下载地址 -
songshuaiyang:
angryid 写道国内的网站,速度还可以jar包下载网站打不 ...
常用jar包下载地址 -
angryid:
国内的网站,速度还可以jar包下载网站
常用jar包下载地址 -
angryid:
我必须要评论一下,我发现一个jar包下载网站,javaeye的 ...
常用jar包下载地址
http://blog.sina.com.cn/s/blog_401a71d1010005cc.html
ScheduleIterator.java
import java.util.Calendar;
import java.util.Date;
public class ScheduleIterator {
private final int hourOfDay, minute, second;
private final Calendar calendar = Calendar.getInstance();
public ScheduleIterator(int month, int day, int hourOfDay, int minute,
int second) {
this(month, day, hourOfDay, minute, second, new Date());
}
public ScheduleIterator(int month, int day, int hourOfDay, int minute,
int second, Date date) {
this.hourOfDay = hourOfDay;
this.minute = minute;
this.second = second;
calendar.setTime(date);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, day);
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
calendar.set(Calendar.SECOND, second);
calendar.set(Calendar.MILLISECOND, 0);
if (!calendar.getTime().before(date)) {
calendar.add(Calendar.DATE, -1);
}
}
public Date next() {
calendar.add(Calendar.MINUTE, 1);
return calendar.getTime();
}
}
Scheduler.java
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class Scheduler {
class SchedulerTimerTask
extends TimerTask {
private SchedulerTask schedulerTask;
private ScheduleIterator iterator;
public SchedulerTimerTask(SchedulerTask schedulerTask,
ScheduleIterator iterator) {
this.schedulerTask = schedulerTask;
this.iterator = iterator;
}
public void run() {
schedulerTask.run();
reschedule(schedulerTask, iterator);
}
}
private final Timer timer = new Timer();
public Scheduler() {
}
/**
* Terminates this <code>Scheduler</code>, discarding any currently scheduled tasks. Does not interfere with a currently executing task (if it exists). Once a scheduler has been terminated, its execution thread terminates gracefully, and no more tasks may be scheduled on it.
* <p>
* Note that calling this method from within the run method of a scheduler task that was invoked by this scheduler absolutely guarantees that the ongoing task execution is the last task execution that will ever be performed by this scheduler.
* <p>
* This method may be called repeatedly; the second and subsequent calls have no effect.
*/
public void cancel() {
timer.cancel();
}
/**
* Schedules the specified task for execution according to the specified schedule. If times specified by the <code>ScheduleIterator</code> are in the past they are scheduled for immediate execution.
* <p>
* @param schedulerTask task to be scheduled
* @param iterator iterator that describes the schedule
* @throws IllegalStateException if task was already scheduled or cancelled, scheduler was cancelled, or scheduler thread terminated.
*/
public void schedule(SchedulerTask schedulerTask,
ScheduleIterator iterator) {
Date time = iterator.next();
if (time == null) {
schedulerTask.cancel();
}
else {
synchronized (schedulerTask.lock) {
if (schedulerTask.state != SchedulerTask.VIRGIN) {
throw new IllegalStateException("Task already scheduled " +
"or cancelled");
}
schedulerTask.state = SchedulerTask.SCHEDULED;
schedulerTask.timerTask =
new SchedulerTimerTask(schedulerTask, iterator);
System.out.println("time:s=" + schedulerTask.timerTask + "time:t=" +
time.toLocaleString());
timer.schedule(schedulerTask.timerTask, time);
}
}
}
private void reschedule(SchedulerTask schedulerTask,
ScheduleIterator iterator) {
Date time = iterator.next();
if (time == null) {
schedulerTask.cancel();
}
else {
synchronized (schedulerTask.lock) {
if (schedulerTask.state != SchedulerTask.CANCELLED) {
schedulerTask.timerTask =
new SchedulerTimerTask(schedulerTask, iterator);
System.out.println("time1:s=" + schedulerTask.timerTask + "time1:t=" +
time.toLocaleString());
timer.schedule(schedulerTask.timerTask, time);
}
}
}
}
}
SchedulerTask.java
import java.util.TimerTask;
/**
* A task that can be scheduled for recurring execution by a {@link Scheduler}.
*/
public abstract class SchedulerTask
implements Runnable {
final Object lock = new Object();
int state = VIRGIN;
static final int VIRGIN = 0;
static final int SCHEDULED = 1;
static final int CANCELLED = 2;
TimerTask timerTask;
protected SchedulerTask() {
}
public abstract void run();
public boolean cancel() {
synchronized (lock) {
if (timerTask != null) {
timerTask.cancel();
}
boolean result = (state == SCHEDULED);
state = CANCELLED;
return result;
}
}
public long scheduledExecutionTime() {
synchronized (lock) {
return timerTask == null ? 0 : timerTask.scheduledExecutionTime();
}
}
}
AlarmClock.java
import java.text.SimpleDateFormat;
import java.util.Date;
import java.sql.*;
public class AlarmClock {
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;
private final Scheduler scheduler = new Scheduler();
private final SimpleDateFormat dateFormat =
new SimpleDateFormat("dd MMM yyyy HH:mm:ss.SSS");
private final int month, day, hourOfDay, minute, second;
private final String content;
public AlarmClock(int month, int day, int hourOfDay, int minute, int second,
String content) {
this.month = month;
this.day = day;
this.hourOfDay = hourOfDay;
this.minute = minute;
this.second = second;
this.content = content;
}
public void start() {
scheduler.schedule(new SchedulerTask() {
public void run() {
soundAlarm();
}
private void soundAlarm() {
// 在这里放要执行的东西
System.out.println( "我* . 执行到这儿了. "+content);
}
}
, new ScheduleIterator(month, day, hourOfDay, minute, second));
}
public static void main(String[] args) {
AlarmClock alarmClock = new AlarmClock(3, 14, 16, 31, 40,
"hello world !!!");
alarmClock.start();
}
}
发表评论
-
RSA算法 非对称加密算法/数字签名算法
2015-12-09 16:42 937转自 http://security.group.iteye ... -
加密解密、签名验签
2015-12-09 16:29 460转自http://lvbin0502.iteye.com/b ... -
深入理解JVM
2014-09-25 17:32 684转自 http://blog.sina.com.cn/s/b ... -
LinkedHashMap和HashMap、HashTable的比较使用
2014-07-11 09:45 821转自 http://www.cnblogs.com/hubi ... -
java日期函数处理
2013-09-29 16:53 936Calendar cal = GregorianCalenda ... -
对象池技术
2011-03-21 17:11 59161 对象池技术的原理: 对象池技术在服务器开发上应用 ... -
JAVA开发者最常去的20个英文网站
2011-03-21 16:58 958转自 http://topmanopensource. ... -
日期工具类
2011-02-16 16:34 1050转自 http://www.iteye.com/topic/ ... -
log4j
2011-01-27 09:05 974好处:便于维护与管理,如果系统崩溃或被黑客攻击,查日志就知 ... -
正则顺口溜
2011-01-22 11:21 996http://cons-mora.iteye.com/blog ... -
Pattern和Matcher
2011-01-22 11:00 2487转载 http://liujinpan75.iteye.com ... -
java正则表达式
2011-01-22 10:35 940http://geeksun.iteye.com/blog/3 ... -
正则表达式的用法
2011-01-22 10:31 880http://cool1314521ok-qq-com.ite ... -
java定时器 schedule和scheduleAtFixedRate区别
2011-01-12 16:57 7473转自http://wangzjie.iteye.c ... -
java定时器案例
2011-01-12 15:52 1265转自http://tomenjoy.iteye.com/blo ... -
java定时器
2011-01-12 15:45 902转自 http://qinshanwu.iteye.com/b ... -
java对象的序列化和反序列化
2010-12-28 22:07 800转自http://www.iteye.com/topi ... -
架构师面试题参考
2010-12-11 13:30 9963一、牛人出的面试题如 ... -
Java的垃圾回收机制
2010-12-11 13:28 1171Java的垃圾回收机制是Java虚拟机提供的能力,用于在空闲时 ... -
HttpSession理解
2010-12-10 13:37 46751 如果在jsp中没有显式使用 <%@page ses ...
相关推荐
定时启动任务线程,执行任务。通过设置calendar.add(Calendar.SECOND, 900);//15分钟 隔多少秒执行扫描一次
Quartz定时执行提醒,间断执行测试案例
Python代码源码-实操案例-框架案例-如何在Windows系统下定时执行Python程序.zip
C#实现的自定义定时任务 可定时运行 多任务运行
一般定时任务配置都需要相互的依赖,代码量多也不简洁,也得有任务管理器管理,此版本的定时任务本着简洁而去配置只需两步 ...二,相对的类和方法 <bean id="myTaskXml" class="test.task"></bean>
不知道能程序的性能会不会影响很大! 复制代码 代码如下: ignore_user_abort();... 您可能感兴趣的文章:php定时计划任务的实现方法详解php中定时计划任务的实现原理PHP定时执行计划任务的多种方法小结PHP定时执行
案例1O 动态调用可执行EXE文件 案例11 动态查看和修改文件属性 案例12 动态比较文件 本章小结 第9章 VisualC#2008算法及控件的应用 案例1 利用冒泡算法实现从小到大排序 案例2 利用希尔算法实现从大到小排序 案例3 ...
案例1O 动态调用可执行EXE文件 案例11 动态查看和修改文件属性 案例12 动态比较文件 本章小结 第9章 VisualC#2008算法及控件的应用 案例1 利用冒泡算法实现从小到大排序 案例2 利用希尔算法实现从大到小排序 案例3 ...
<br>二、内容 <br> 本光碟中包含图书中的每个案例的源代码、可执行文件和所有资源文件,具体组织结构如下: 第1章 窗体与控件 案例1 创建应用、窗口与控件 案例2 目录浏览器 案例3 文件...
案例10 动态调用可执行EXE文件 案例11 动态查看和修改文件属性 案例12 动态比较文件 本章小结 第9章 Visual C#2008算法及控件的应用 案例1 利用冒泡算法实现从小到大排序 案例2 利用希尔算法实现从大到小排序 ...
我们通常写的timer都是用main方法写的定时器,但同样我们也需要根据服务器启动后定时器也启动的 定时执行任务。不过有个致命伤就是集群方面跟quartz不能比,此方法代码做参考不错,如果要用,那么这个方法在一台...
案例1O 动态调用可执行EXE文件 案例11 动态查看和修改文件属性 案例12 动态比较文件 本章小结 第9章 VisualC#2008算法及控件的应用 案例1 利用冒泡算法实现从小到大排序 案例2 利用希尔算法实现从大到小排序 案例3 ...
PHP定时执行的三种方式实现 1、windows 的计划任务 2、linux的脚本程序 3、让web浏览器定时刷新 具体实现 windows计划任务 PHP很少在win服务器上跑,具体实现也不再深究,看网上实现的原理大概是写bat脚本,然后让...
本案例实现利用Spring技术实现定时任务功能,用于Web项目
自己用Spring、Quartz集合freemarker 实现了一个定时执行模板或者jsp等文件转化为html页面的案例,里面每步都写了注释,比较适合没有接触过,但是又想了解定时生成页面的朋友.希望对大家有帮助,谢谢!
简单案例 定时任务执行带参数的方法 通过NuGet安装Install-Package Quartz
这个文件包含了xxl-job的定时调度中心源码、执行器demo源码,需要的可以下载。
第二章 捕获鼠标绘图 捕捉屏幕图像 获取屏幕上颜色 界面上实现3D文字 列举当前系统的字体 判知BMP图片的大小 图片的伸缩显示 显示资源位图 游览大图 第三章 CArray类的应用 CListCtrl 控件的应用 IP Address控件编辑...
spring+Quartz定时任务:主要是白天的一些不是需要很实时性的东西放到夜间执行、还有一些统计性的问题。 OsCache缓存框架:是一款相对来说比较不错的缓存框架、可以缓存对象、也可以缓存单个页面、可以很好的减少...