这个关于Timer的学习,好像这个可以做为触发器之类的东东~~~
[code]package com.test;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
public class HelloWorldTasker extends TimerTask {
@Override
public void run() {
System.out.pringln("Hello World");
}
public static void main(String[] args){
long MILLIS_IN_YEAR=1000 * 60 * 60 * 24 * 365;
System.out.println(MILLIS_IN_YEAR);
Timer timer=new Timer();
HelloWorldTasker helloWorldTasker=new HelloWorldTasker();
//schedule以固定的延迟执行helloWorldTasker
//timer.schedule(helloWorldTasker, 1000, 1000);
//scheduleAtFixedRate以固定的周期运行helloWorldTasker
//timer.scheduleAtFixedRate(helloWorldTasker, 1000, 1000);
// use a date instead
Calendar cal = Calendar.getInstance();
cal.set(2007, Calendar.NOVEMBER, 31);
//schedule安排在指定的时间执行指定的任务
//timer.schedule(helloWorldTasker, cal.getTime());
System.out.println(cal.getTime());
timer.scheduleAtFixedRate(helloWorldTasker, cal.getTime(), MILLIS_IN_YEAR);
}
}
[/code]
[code]package com.test;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
public class HelloWorldTasker extends TimerTask {
@Override
public void run() {
System.out.pringln("Hello World");
}
public static void main(String[] args){
long MILLIS_IN_YEAR=1000 * 60 * 60 * 24 * 365;
System.out.println(MILLIS_IN_YEAR);
Timer timer=new Timer();
HelloWorldTasker helloWorldTasker=new HelloWorldTasker();
//schedule以固定的延迟执行helloWorldTasker
//timer.schedule(helloWorldTasker, 1000, 1000);
//scheduleAtFixedRate以固定的周期运行helloWorldTasker
//timer.scheduleAtFixedRate(helloWorldTasker, 1000, 1000);
// use a date instead
Calendar cal = Calendar.getInstance();
cal.set(2007, Calendar.NOVEMBER, 31);
//schedule安排在指定的时间执行指定的任务
//timer.schedule(helloWorldTasker, cal.getTime());
System.out.println(cal.getTime());
timer.scheduleAtFixedRate(helloWorldTasker, cal.getTime(), MILLIS_IN_YEAR);
}
}
[/code]