Timer間隔時間delay怎麼理解?

mTimer.schedule(task,delay,period);
//延遲3秒執行一次,然後每個2秒執行一次
mTimer.schedule(,3000,2000);
//延遲0秒執行一次,然後每個2秒執行一次(即不延遲馬上執行一次而不是2秒後執行一次)
mTimer.schedule(,0,2000);

task
TimerTask: task to be scheduled.
delay
long: delay in milliseconds before task is to be executed.
period
long: time in milliseconds between successive task executions.
public class Dingshiqi {
	public static void main(String[] args) {
		System.out.println(formatTime(System.currentTimeMillis()+""));
		Timer mTimer = new Timer();
		mTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                //                調用識別結果進度查詢接口
            	

            	System.out.println(formatTime(System.currentTimeMillis()+""));
            	
            	
            	
            }

			
        }, 3000, 2000);//延遲3秒執行一次,然後每個2秒執行一次
	}
	private static Date formatTime(String d) {
		Date date=new Date();
		// TODO Auto-generated method stub
		SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	
//    	System.out.println("��ǰ����Ϊ��"+simpleDateFormat.format(date));
    	try {
			date=simpleDateFormat.parse(d);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return date;
	}
}

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