Skip to content

Commit

Permalink
Property-driven onRefresh exit for AppCDS purpose
Browse files Browse the repository at this point in the history
This commit allows to terminate the JVM when the
-Dspring.context.exit=onRefresh property is set,
which can be useful for AppCDS training run in order
to get most of the AppCDS cache without starting the
beans.

Closes spring-projectsgh-31595
  • Loading branch information
sdeleuze committed Nov 13, 2023
1 parent 258f99a commit eb3982b
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,32 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
/**
* Property name for a common context checkpoint: {@value}.
* @since 6.1
* @see #CHECKPOINT_ON_REFRESH_VALUE
* @see #ON_REFRESH_VALUE
* @see org.crac.Core#checkpointRestore()
*/
public static final String CHECKPOINT_PROPERTY_NAME = "spring.context.checkpoint";

/**
* Recognized value for the context checkpoint property: {@value}.
* Property name for terminating the JVM when the context reaches a specific phase: {@value}.
* @since 6.1
* @see #ON_REFRESH_VALUE
*/
public static final String EXIT_PROPERTY_NAME = "spring.context.exit";

/**
* Recognized value for the context checkpoint and exit properties: {@value}.
* @since 6.1
* @see #CHECKPOINT_PROPERTY_NAME
* @see org.crac.Core#checkpointRestore()
* @see #EXIT_PROPERTY_NAME
*/
public static final String CHECKPOINT_ON_REFRESH_VALUE = "onRefresh";
public static final String ON_REFRESH_VALUE = "onRefresh";


private static final boolean checkpointOnRefresh =
CHECKPOINT_ON_REFRESH_VALUE.equalsIgnoreCase(SpringProperties.getProperty(CHECKPOINT_PROPERTY_NAME));
ON_REFRESH_VALUE.equalsIgnoreCase(SpringProperties.getProperty(CHECKPOINT_PROPERTY_NAME));

private static final boolean exitOnRefresh =
ON_REFRESH_VALUE.equalsIgnoreCase(SpringProperties.getProperty(EXIT_PROPERTY_NAME));

private final Log logger = LogFactory.getLog(getClass());

Expand Down Expand Up @@ -182,6 +192,9 @@ public void onRefresh() {
if (checkpointOnRefresh) {
new CracDelegate().checkpointRestore();
}
if (exitOnRefresh) {
Runtime.getRuntime().halt(0);
}

this.stoppedBeans = null;
try {
Expand Down

0 comments on commit eb3982b

Please sign in to comment.