java Timer 定時器

try
{
// 每天2點,從數據庫重新讀取數據
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
if (calendar.get(Calendar.HOUR_OF_DAY) >= 2)
{
calendar.add(Calendar.DAY_OF_YEAR, 1);
}
calendar.set(Calendar.HOUR_OF_DAY, 2);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);


Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask()
{
public void run()
{
refreshAll();
}
}, calendar.getTime(), 24 * 60 * 60 * 1000);


} catch (Exception e)
{
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章