日期:2014-05-20 浏览次数:20726 次
public class Cs {
public static SimpleDateFormat sd = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE, 1);
c.set(Calendar.HOUR_OF_DAY, 9);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
Date time = c.getTime();
Timer timer = new Timer();
System.out.println("1: " + sd.format(time));
timer.schedule(new TimerTask() {
public void run() {
System.out.println("get in timer!!!!");
}
}, time);
}
}
private void mainLoop() {
while (true) {
try {
TimerTask task;
boolean taskFired;
synchronized(queue) {
// Wait for queue to become non-empty
while (queue.isEmpty() && newTasksMayBeScheduled)
queue.wait();
if (queue.isEmpty())
break; // Queue is empty and will forever remain; die
// Queue nonempty; look at first evt and do the right thing
long currentTime, executionTime;
task = queue.getMin(); // 得到最近所需执行的任务
synchronized(task.lock) {
if (task.state == TimerTask.CANCELLED) {
queue.removeMin();