並非所有的系統中發生的事情都是由用戶主動引發的
package com
import java
import java
import java
public class TimeTask extends TimerTask {
@Override
public void run() {
//沒有秒鐘
SimpleDateFormat sdf=new SimpleDateFormat(
System
}
}
package com
import java
/**
* @author Administrator
*
*/
public class Hello {
public static void main(String[] args) throws Exception {
Timer timer=new Timer();
timer
}
}
schedule(TimerTask task
我們可以看到
創建一項任務
public class Shedule {
//this class do daily task for message awoke and cycle task
public Shedule() {
}
public void say(){
//cycleTask();
messageAwoke();
}
}
package com
import org
import org
import org
public class DailySay extends QuartzJobBean {
private Shedule sh ;
@Override
protected void executeInternal(JobExecutionContext arg
throws JobExecutionException {
sh
}
public Shedule getSh() {
return sh;
}
public void setSh(Shedule sh) {
this
}
}
我們使用Spring的注入容器注入Shedule
在Spring配置文件中
<bean id=
<property name=
</bean>
<bean id=
<property name=
<property name=
<map>
<entry key=
</map>
</property>
</bean>
<bean id=
<property name=
<property name=
</bean>
<bean id=
<property name=
<list>
<ref bean=
</list>
</property>
</bean>
這樣你將會完成每天凌晨
From:http://tw.wingwit.com/Article/program/Java/ky/201311/28595.html