Skip to content

Commit 43ecb0b

Browse files
committed
Eagerly initialize ZERO_NANOS constant
1 parent 0e5edc4 commit 43ecb0b

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

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

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,14 @@
2929
* Created using the {@code parse*} methods.
3030
*
3131
* @author Arjen Poutsma
32+
* @author Juergen Hoeller
3233
* @since 5.3
3334
*/
3435
final class BitsCronField extends CronField {
3536

36-
private static final long MASK = 0xFFFFFFFFFFFFFFFFL;
37-
38-
39-
@Nullable
40-
private static BitsCronField zeroNanos = null;
37+
public static final BitsCronField ZERO_NANOS = forZeroNanos();
4138

39+
private static final long MASK = 0xFFFFFFFFFFFFFFFFL;
4240

4341
// we store at most 60 bits, for seconds and minutes, so a 64-bit long suffices
4442
private long bits;
@@ -48,16 +46,14 @@ private BitsCronField(Type type) {
4846
super(type);
4947
}
5048

49+
5150
/**
5251
* Return a {@code BitsCronField} enabled for 0 nanoseconds.
5352
*/
54-
public static BitsCronField zeroNanos() {
55-
if (zeroNanos == null) {
56-
BitsCronField field = new BitsCronField(Type.NANO);
57-
field.setBit(0);
58-
zeroNanos = field;
59-
}
60-
return zeroNanos;
53+
private static BitsCronField forZeroNanos() {
54+
BitsCronField field = new BitsCronField(Type.NANO);
55+
field.setBit(0);
56+
return field;
6157
}
6258

6359
/**
@@ -108,7 +104,6 @@ public static BitsCronField parseDaysOfWeek(String value) {
108104
return result;
109105
}
110106

111-
112107
private static BitsCronField parseDate(String value, BitsCronField.Type type) {
113108
if (value.equals("?")) {
114109
value = "*";
@@ -174,6 +169,7 @@ private static ValueRange parseRange(String value, Type type) {
174169
}
175170
}
176171

172+
177173
@Nullable
178174
@Override
179175
public <T extends Temporal & Comparable<? super T>> T nextOrSame(T temporal) {
@@ -217,7 +213,6 @@ private int nextSetBit(int fromIndex) {
217213
else {
218214
return -1;
219215
}
220-
221216
}
222217

223218
private void setBits(ValueRange range) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/**
3131
* Single field in a cron pattern. Created using the {@code parse*} methods,
32-
* main and only entry point is {@link #nextOrSame(Temporal)}.
32+
* the main and only entry point is {@link #nextOrSame(Temporal)}.
3333
*
3434
* <p>Supports a Quartz day-of-month/week field with an L/# expression. Follows
3535
* common cron conventions in every other respect, including 0-6 for SUN-SAT
@@ -60,7 +60,7 @@ protected CronField(Type type) {
6060
* Return a {@code CronField} enabled for 0 nanoseconds.
6161
*/
6262
public static CronField zeroNanos() {
63-
return BitsCronField.zeroNanos();
63+
return BitsCronField.ZERO_NANOS;
6464
}
6565

6666
/**
@@ -186,7 +186,6 @@ protected enum Type {
186186
MONTH(ChronoField.MONTH_OF_YEAR, ChronoUnit.YEARS, ChronoField.DAY_OF_MONTH, ChronoField.HOUR_OF_DAY, ChronoField.MINUTE_OF_HOUR, ChronoField.SECOND_OF_MINUTE, ChronoField.NANO_OF_SECOND),
187187
DAY_OF_WEEK(ChronoField.DAY_OF_WEEK, ChronoUnit.WEEKS, ChronoField.HOUR_OF_DAY, ChronoField.MINUTE_OF_HOUR, ChronoField.SECOND_OF_MINUTE, ChronoField.NANO_OF_SECOND);
188188

189-
190189
private final ChronoField field;
191190

192191
private final ChronoUnit higherOrder;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ public static boolean isQuartzDaysOfMonthField(String value) {
7575
}
7676

7777
/**
78-
* Parse the given value into a days of months {@code QuartzCronField}, the fourth entry of a cron expression.
79-
* Expects a "L" or "W" in the given value.
78+
* Parse the given value into a days of months {@code QuartzCronField},
79+
* the fourth entry of a cron expression.
80+
* <p>Expects a "L" or "W" in the given value.
8081
*/
8182
public static QuartzCronField parseDaysOfMonth(String value) {
8283
int idx = value.lastIndexOf('L');

0 commit comments

Comments
 (0)