Skip to content

Commit 5a7b3f6

Browse files
committed
added "repeatCount" bean property to Quartz SimpleTriggerFactoryBean
Issue: SPR-9521
1 parent fdb9de1 commit 5a7b3f6

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

spring-context-support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,9 @@ public void setJobDataAsMap(Map<String, ?> jobDataAsMap) {
145145
* Set the start delay in milliseconds.
146146
* <p>The start delay is added to the current system time (when the bean starts)
147147
* to control the start time of the trigger.
148-
* @param startDelay the start delay, in milliseconds
149148
*/
150149
public void setStartDelay(long startDelay) {
151-
Assert.state(startDelay >= 0, "Start delay cannot be negative.");
150+
Assert.isTrue(startDelay >= 0, "Start delay cannot be negative");
152151
this.startDelay = startDelay;
153152
}
154153

spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ public class SimpleTriggerFactoryBean implements FactoryBean<SimpleTrigger>, Bea
8282

8383
private long repeatInterval;
8484

85+
private int repeatCount = -1;
86+
8587
private int priority;
8688

8789
private int misfireInstruction;
@@ -143,10 +145,9 @@ public void setJobDataAsMap(Map<String, ?> jobDataAsMap) {
143145
* Set the start delay in milliseconds.
144146
* <p>The start delay is added to the current system time (when the bean starts)
145147
* to control the start time of the trigger.
146-
* @param startDelay the start delay, in milliseconds
147148
*/
148149
public void setStartDelay(long startDelay) {
149-
Assert.state(startDelay >= 0, "Start delay cannot be negative.");
150+
Assert.isTrue(startDelay >= 0, "Start delay cannot be negative");
150151
this.startDelay = startDelay;
151152
}
152153

@@ -157,6 +158,14 @@ public void setRepeatInterval(long repeatInterval) {
157158
this.repeatInterval = repeatInterval;
158159
}
159160

161+
/**
162+
* Specify the number of times this trigger is supposed to fire.
163+
* <p>Default is to repeat indefinitely.
164+
*/
165+
public void setRepeatCount(int repeatCount) {
166+
this.repeatCount = repeatCount;
167+
}
168+
160169
/**
161170
* Specify the priority of this trigger.
162171
*/
@@ -216,6 +225,7 @@ else if (this.startTime == null) {
216225
sti.setJobDataMap(this.jobDataMap);
217226
sti.setStartTime(this.startTime);
218227
sti.setRepeatInterval(this.repeatInterval);
228+
sti.setRepeatCount(this.repeatCount);
219229
sti.setPriority(this.priority);
220230
sti.setMisfireInstruction(this.misfireInstruction);
221231
this.simpleTrigger = sti;
@@ -248,7 +258,7 @@ else if (this.startTime == null) {
248258
pvs.add("jobDataMap", this.jobDataMap);
249259
pvs.add("startTime", this.startTime);
250260
pvs.add("repeatInterval", this.repeatInterval);
251-
pvs.add("repeatCount", -1);
261+
pvs.add("repeatCount", this.repeatCount);
252262
pvs.add("priority", this.priority);
253263
pvs.add("misfireInstruction", this.misfireInstruction);
254264
bw.setPropertyValues(pvs);

0 commit comments

Comments
 (0)