/**
*@author qingbao-gao
*<p>Blog:http://www.cnweblog.com/nm1504</p>
*<p>E-mail:yyk1504@163.com</p>
*<p>创建时间:2008-1-23-上午10:43:20</p>
*<p>Copyright: (c)2008-1-23</p>
*/
package com.mfsoft.net.task;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.log4j.*;
public class TaskJob
{
public static void main(String[] args)
{
TaskJob tj=new TaskJob();
//每月的24号下午16点26分启动任务
tj.task(24, 16, 26, 0);
}
public void task(int day,int hour,int minute,int second)
{
PickTask pt = new PickTask();
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_MONTH, day);
c.set(Calendar.HOUR_OF_DAY, hour);
c.set(Calendar.MINUTE, minute);
c.set(Calendar.SECOND, second);
pt.start(c.getTime());
}
}
class PickTask
{
private Timer timer;
public PickTask()
{
timer = new Timer();
}
private TimerTask task = new TimerTask()
{
public void run()
{
System.out.println("定时任务启动...");
//你要启动的任务代码
}
};
public void start( Date date)
{
timer.schedule(task,date);
}
}