Java计时器Timer和TimerTask用法

 1 package com.sy.game.test;
 2 
 3 import java.util.Timer;
 4 import java.util.TimerTask;
 5 
 6 public class TimeTask {   
 7    
 8     public static void main(String[] args) { 
 9         TimeTask tTask=new TimeTask();
10         tTask.timeVoid();
11     }
12     
13     public void timeVoid(){
14         final Timer timer = new Timer();
15         TimerTask tt=new TimerTask() { 
16             @Override
17             public void run() {
18                 System.out.println("到点啦!");
19                 timer.cancel();
20             }
21         };
22         timer.schedule(tt, 3000);
23     }
24 }

 

posted @ 2016-07-16 10:20  Web1024  阅读(407)  评论(0编辑  收藏  举报