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