Skip to content

Commit 0e73213

Browse files
authored
Add ApplicationEvent constructor for specifying timestamp
Closes gh-26871
1 parent 1e1045b commit 0e73213

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

spring-context/src/main/java/org/springframework/context/ApplicationEvent.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.context;
1818

19+
import java.time.Clock;
1920
import java.util.EventObject;
2021

2122
/**
@@ -46,6 +47,17 @@ public ApplicationEvent(Object source) {
4647
this.timestamp = System.currentTimeMillis();
4748
}
4849

50+
/**
51+
* Create a new {@code ApplicationEvent} with a fixed timestamp.
52+
* @param source the object on which the event initially occurred or with
53+
* which the event is associated (never {@code null})
54+
* @param clock a clock which will provide the timestamp
55+
*/
56+
public ApplicationEvent(Object source, Clock clock) {
57+
super(source);
58+
this.timestamp = clock.millis();
59+
}
60+
4961

5062
/**
5163
* Return the system time in milliseconds when the event occurred.

0 commit comments

Comments
 (0)