From 0e732131444e2602845fd12dfdcb36d8a962fe81 Mon Sep 17 00:00:00 2001 From: Michael Edwards Date: Wed, 26 May 2021 14:32:41 +0200 Subject: [PATCH] Add ApplicationEvent constructor for specifying timestamp Closes gh-26871 --- .../springframework/context/ApplicationEvent.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spring-context/src/main/java/org/springframework/context/ApplicationEvent.java b/spring-context/src/main/java/org/springframework/context/ApplicationEvent.java index 5906c596a7..f54d7b91c8 100644 --- a/spring-context/src/main/java/org/springframework/context/ApplicationEvent.java +++ b/spring-context/src/main/java/org/springframework/context/ApplicationEvent.java @@ -16,6 +16,7 @@ package org.springframework.context; +import java.time.Clock; import java.util.EventObject; /** @@ -46,6 +47,17 @@ public abstract class ApplicationEvent extends EventObject { this.timestamp = System.currentTimeMillis(); } + /** + * Create a new {@code ApplicationEvent} with a fixed timestamp. + * @param source the object on which the event initially occurred or with + * which the event is associated (never {@code null}) + * @param clock a clock which will provide the timestamp + */ + public ApplicationEvent(Object source, Clock clock) { + super(source); + this.timestamp = clock.millis(); + } + /** * Return the system time in milliseconds when the event occurred.