package com.northeasttycoon.service;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* describe : 指定某一時間點執行任務操作
* @author northeasttycoon
*/
public class ServiceBusiness implements IServiceBusiness {
final private static Log log = LogFactory.getLog(ServiceBusiness.class);
public ServiceBusiness() {
}
public void testTimer() throws Exception {
// 時間類
Calendar startDate = Calendar.getInstance();
//設置開始執行的時間為 某年-某月-某月 00:00:00
startDate.set(startDate.get(Calendar.YEAR), startDate.get(Calendar.MONTH), startDate.get(Calendar.DATE), 15, 10, 0);
// 1小時的毫秒設定
long timeInterval = 60 * 60 * 1000;
// 定時器實例
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
// 定時器主要執行的代碼塊
System.out.println("定時器主要執行的代碼!"+CommonUtil.GetNowDateTime());
}
// 設定的定時器在15:10分開始執行,每隔 1小時執行一次.
}, startDate.getTime(), timeInterval ); //timeInterval 是一天的毫秒數,也是執行間隔
};
public static void main(String[] args) throws Exception {
ServiceBusiness business = new ServiceBusiness();
business.testTimer();
}
