Skip to content

Commit d99c2cf

Browse files
committed
Refine JVM checkpoint/restore support
This commit: - Refine the wording used in logs and Javadoc - Avoid calling awaitPreventShutdownBarrier() in afterRestore() - Add logs to print the restart duration See gh-29921
1 parent ffa431d commit d99c2cf

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

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

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

1717
package org.springframework.context.support;
1818

19+
import java.time.Duration;
1920
import java.util.ArrayList;
2021
import java.util.Collections;
2122
import java.util.Comparator;
@@ -54,7 +55,7 @@
5455
* <p>Provides interaction with {@link Lifecycle} and {@link SmartLifecycle} beans in
5556
* groups for specific phases, on startup/shutdown as well as for explicit start/stop
5657
* interactions on a {@link org.springframework.context.ConfigurableApplicationContext}.
57-
* As of 6.1, this also includes support for JVM snapshot checkpoints (Project CRaC).
58+
* As of 6.1, this also includes support for JVM checkpoint/restore (Project CRaC).
5859
*
5960
* @author Mark Fisher
6061
* @author Juergen Hoeller
@@ -456,7 +457,7 @@ private record LifecycleGroupMember(String name, Lifecycle bean) {}
456457
private class CracDelegate {
457458

458459
public Object registerResource() {
459-
logger.debug("Registering JVM snapshot callback for Spring-managed lifecycle beans");
460+
logger.debug("Registering JVM checkpoint/restore callback for Spring-managed lifecycle beans");
460461
CracResourceAdapter resourceAdapter = new CracResourceAdapter();
461462
org.crac.Core.getGlobalContext().register(resourceAdapter);
462463
return resourceAdapter;
@@ -466,7 +467,7 @@ public Object registerResource() {
466467

467468
/**
468469
* Resource adapter for Project CRaC, triggering a stop-and-restart cycle
469-
* for Spring-managed lifecycle beans around a JVM snapshot checkpoint.
470+
* for Spring-managed lifecycle beans around a JVM checkpoint/restore.
470471
* @since 6.1
471472
* @see #stopForRestart()
472473
* @see #restartAfterStop()
@@ -491,18 +492,21 @@ public void beforeCheckpoint(org.crac.Context<? extends org.crac.Resource> conte
491492
thread.start();
492493
awaitPreventShutdownBarrier();
493494

494-
logger.debug("Stopping Spring-managed lifecycle beans before JVM snapshot checkpoint");
495+
logger.debug("Stopping Spring-managed lifecycle beans before JVM checkpoint");
495496
stopForRestart();
496497
}
497498

498499
@Override
499500
public void afterRestore(org.crac.Context<? extends org.crac.Resource> context) {
500-
logger.debug("Restarting Spring-managed lifecycle beans after JVM snapshot restore");
501+
long restartTime = System.nanoTime();
502+
logger.debug("Restarting Spring-managed lifecycle beans after JVM restore");
501503
restartAfterStop();
502504

503505
// Barrier for prevent-shutdown thread not needed anymore
504-
awaitPreventShutdownBarrier();
505506
this.barrier = null;
507+
508+
Duration timeTakenToRestart = Duration.ofNanos(System.nanoTime() - restartTime);
509+
logger.debug("Restart complete in " + timeTakenToRestart.toMillis() + " ms");
506510
}
507511

508512
private void awaitPreventShutdownBarrier() {

0 commit comments

Comments
 (0)