KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > tasks > timer > StoppableTimer


1 package com.sslexplorer.tasks.timer;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5 import java.util.Timer JavaDoc;
6 import java.util.TimerTask JavaDoc;
7
8 public class StoppableTimer extends Timer JavaDoc {
9
10     public static String JavaDoc NAME = "stoppable.timer";
11
12     Map JavaDoc tasks = new HashMap JavaDoc();
13     
14     public StoppableTimer() {
15         super();
16     }
17
18     public StoppableTimer(boolean isDaemon) {
19         super(isDaemon);
20     }
21     
22     public TimerTask JavaDoc getTimerTask(String JavaDoc taskName) {
23         return (TimerTask JavaDoc)tasks.get(taskName);
24     }
25
26     public void schedule(String JavaDoc taskName, TimerTask JavaDoc timerTask, long delay) {
27         super.schedule(timerTask, delay);
28         tasks.put(taskName, timerTask);
29     }
30     
31     public void cancelTimerTask(String JavaDoc taskName){
32         ((TimerTask JavaDoc) tasks.get(taskName)).cancel() ;
33         tasks.remove(taskName);
34     }
35     
36     public boolean containsTimerTask(String JavaDoc taskName){
37         return tasks.containsKey(taskName);
38     }
39 }
40
Popular Tags