2013-05-18 5 views
0

, 나는 타이머에 대해 다음 코드를 사용하고 작업에 타이머를 중지합니다 나중에 경우자바는 자바에서

Timer timer = new Timer("WeatherUpdate"); 
MyTask t = new MyTask(); 
timer.schedule(t, 10000, 10000); 

class MyTask extends TimerTask 
{ 
    public void run() 
    { 
     PlaceWeatherObjectsInSpace(); 
    } 
} 

, 나는이 타이머를 중단하고자하는 가장 좋은 방법으로는 무엇인가 코드?

tTimerTask

또는

class MyTask extends TimerTask 
{ 

    public void run() 
    { 
     if(taskHasToEnd) { //taskHasToEnd can be any boolean expression comparing current date with the 'date' at which the task should end 
      cancel(); 
     } 
     PlaceWeatherObjectsInSpace(); 
    } 
} 

t.cancel();입니다

답변