1 16 17 package org.springframework.scheduling.timer; 18 19 import java.util.TimerTask ; 20 21 41 public class ScheduledTimerTask { 42 43 private TimerTask timerTask; 44 45 private long delay = 0; 46 47 private long period = -1; 48 49 private boolean fixedRate = false; 50 51 52 60 public ScheduledTimerTask() { 61 } 62 63 68 public ScheduledTimerTask(TimerTask timerTask) { 69 this.timerTask = timerTask; 70 } 71 72 78 public ScheduledTimerTask(TimerTask timerTask, long delay) { 79 this.timerTask = timerTask; 80 this.delay = delay; 81 } 82 83 90 public ScheduledTimerTask(TimerTask timerTask, long delay, long period, boolean fixedRate) { 91 this.timerTask = timerTask; 92 this.delay = delay; 93 this.period = period; 94 this.fixedRate = fixedRate; 95 } 96 97 102 public ScheduledTimerTask(Runnable timerTask) { 103 setRunnable(timerTask); 104 } 105 106 112 public ScheduledTimerTask(Runnable timerTask, long delay) { 113 setRunnable(timerTask); 114 this.delay = delay; 115 } 116 117 124 public ScheduledTimerTask(Runnable timerTask, long delay, long period, boolean fixedRate) { 125 setRunnable(timerTask); 126 this.delay = delay; 127 this.period = period; 128 this.fixedRate = fixedRate; 129 } 130 131 132 136 public void setRunnable(Runnable timerTask) { 137 this.timerTask = new DelegatingTimerTask(timerTask); 138 } 139 140 143 public void setTimerTask(TimerTask timerTask) { 144 this.timerTask = timerTask; 145 } 146 147 150 public TimerTask getTimerTask() { 151 return this.timerTask; 152 } 153 154 159 public void setDelay(long delay) { 160 this.delay = delay; 161 } 162 163 166 public long getDelay() { 167 return this.delay; 168 } 169 170 185 public void setPeriod(long period) { 186 this.period = period; 187 } 188 189 192 public long getPeriod() { 193 return this.period; 194 } 195 196 201 public boolean isOneTimeTask() { 202 return (this.period <= 0); 203 } 204 205 212 public void setFixedRate(boolean fixedRate) { 213 this.fixedRate = fixedRate; 214 } 215 216 219 public boolean isFixedRate() { 220 return this.fixedRate; 221 } 222 223 } 224 | Popular Tags |