Skip to content

Commit 4128f4d

Browse files
committed
Print JVM restoration time in DefaultLifecycleProcessor
Closes gh-31252
1 parent 2fbcff8 commit 4128f4d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

framework-docs/modules/ROOT/pages/integration/checkpoint-restore.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The Spring Framework integrates with checkpoint/restore as implemented by https:
66
Using this feature requires:
77

88
* A checkpoint/restore enabled JVM (Linux only for now).
9-
* The presence in the classpath of the https://github.com/CRaC/org.crac[`org.crac:crac`] library.
9+
* The presence in the classpath of the https://github.com/CRaC/org.crac[`org.crac:crac`] library (version `1.4.0` and above are supported).
1010
* Specifying the required `java` command line parameters like `-XX:CRaCCheckpointTo=PATH` or `-XX:CRaCRestoreFrom=PATH`.
1111

1212
WARNING: The files generated in the path specified by `-XX:CRaCCheckpointTo=PATH` when a checkpoint is requested contain a representation of the memory of the running JVM, which may contain secrets and other sensitive data. Using this feature should be done with the assumption that any value "seen" by the JVM, such as configuration properties coming from the environment, will be stored in those CRaC files. As a consequence, the security implications of where and how those files are generated, stored and accessed should be carefully assessed.

spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.crac.CheckpointException;
3838
import org.crac.Core;
3939
import org.crac.RestoreException;
40+
import org.crac.management.CRaCMXBean;
4041

4142
import org.springframework.beans.factory.BeanFactory;
4243
import org.springframework.beans.factory.BeanFactoryAware;
@@ -59,10 +60,13 @@
5960
* <p>Provides interaction with {@link Lifecycle} and {@link SmartLifecycle} beans in
6061
* groups for specific phases, on startup/shutdown as well as for explicit start/stop
6162
* interactions on a {@link org.springframework.context.ConfigurableApplicationContext}.
62-
* As of 6.1, this also includes support for JVM checkpoint/restore (Project CRaC).
63+
*
64+
* <p>As of 6.1, this also includes support for JVM checkpoint/restore (Project CRaC)
65+
* when the {@code org.crac:crac} dependency on the classpath.
6366
*
6467
* @author Mark Fisher
6568
* @author Juergen Hoeller
69+
* @author Sebastien Deleuze
6670
* @since 3.0
6771
*/
6872
public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactoryAware {
@@ -554,8 +558,10 @@ public void afterRestore(org.crac.Context<? extends org.crac.Resource> context)
554558
// Barrier for prevent-shutdown thread not needed anymore
555559
this.barrier = null;
556560

557-
Duration timeTakenToRestart = Duration.ofNanos(System.nanoTime() - restartTime);
558-
logger.info("Spring-managed lifecycle restart completed in " + timeTakenToRestart.toMillis() + " ms");
561+
long timeTakenToRestart = Duration.ofNanos(System.nanoTime() - restartTime).toMillis();
562+
long timeTakenToRestoreJvm = CRaCMXBean.getCRaCMXBean().getUptimeSinceRestore();
563+
logger.info("Spring-managed lifecycle restart completed in " + timeTakenToRestart
564+
+ " ms (restored JVM running for " + timeTakenToRestoreJvm + " ms)");
559565
}
560566

561567
private void awaitPreventShutdownBarrier() {

0 commit comments

Comments
 (0)