1 16 17 package org.springframework.scheduling.backportconcurrent; 18 19 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit; 20 21 45 public class ScheduledExecutorTask { 46 47 private Runnable runnable; 48 49 private long delay = 0; 50 51 private long period = -1; 52 53 private TimeUnit timeUnit = TimeUnit.MILLISECONDS; 54 55 private boolean fixedRate = false; 56 57 58 65 public ScheduledExecutorTask() { 66 } 67 68 73 public ScheduledExecutorTask(Runnable executorTask) { 74 this.runnable = executorTask; 75 } 76 77 83 public ScheduledExecutorTask(Runnable executorTask, long delay) { 84 this.runnable = executorTask; 85 this.delay = delay; 86 } 87 88 95 public ScheduledExecutorTask(Runnable executorTask, long delay, long period, boolean fixedRate) { 96 this.runnable = executorTask; 97 this.delay = delay; 98 this.period = period; 99 this.fixedRate = fixedRate; 100 } 101 102 103 106 public void setRunnable(Runnable executorTask) { 107 this.runnable = executorTask; 108 } 109 110 113 public Runnable getRunnable() { 114 return this.runnable; 115 } 116 117 122 public void setDelay(long delay) { 123 this.delay = delay; 124 } 125 126 129 public long getDelay() { 130 return this.delay; 131 } 132 133 147 public void setPeriod(long period) { 148 this.period = period; 149 } 150 151 154 public long getPeriod() { 155 return this.period; 156 } 157 158 163 public boolean isOneTimeTask() { 164 return (this.period <= 0); 165 } 166 167 173 public void setTimeUnit(TimeUnit timeUnit) { 174 this.timeUnit = (timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS); 175 } 176 177 180 public TimeUnit getTimeUnit() { 181 return this.timeUnit; 182 } 183 184 191 public void setFixedRate(boolean fixedRate) { 192 this.fixedRate = fixedRate; 193 } 194 195 198 public boolean isFixedRate() { 199 return this.fixedRate; 200 } 201 202 } 203 | Popular Tags |