使用Timer 和 TImeTask 实现 指定时间运行java程序

package scheduled;

 

import java.util.Calendar;

import java.util.Date;

import java.util.Timer;

import java.util.TimerTask;

 

public class TestJavaSched extends TimerTask{

 

@Override

public void run() {

// TODO Auto-generated method stub

System.out.println("开始运行");

}

 

public static void main(String args[]){

Timer time = new Timer();

java.util.Calendar calendar = Calendar.getInstance();

//设置运行时间

calendar.set(Calendar.HOUR_OF_DAY, 9);

calendar.set(Calendar.MINUTE, 1);

calendar.set(Calendar.SECOND, 0);

Date date = calendar.getTime();

 

time.schedule(new TestJavaSched(), date);

}

 

}

 

你可能感兴趣的:(java定时任务)