Browse Source

Property-driven onRefresh exit for AppCDS purpose

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 gh-31595
pull/31123/merge
Sébastien Deleuze 11 months ago
parent
commit
eb3982b6c2
  1. 23
      spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

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

@ -73,22 +73,32 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
/** /**
* Property name for a common context checkpoint: {@value}. * Property name for a common context checkpoint: {@value}.
* @since 6.1 * @since 6.1
* @see #CHECKPOINT_ON_REFRESH_VALUE * @see #ON_REFRESH_VALUE
* @see org.crac.Core#checkpointRestore() * @see org.crac.Core#checkpointRestore()
*/ */
public static final String CHECKPOINT_PROPERTY_NAME = "spring.context.checkpoint"; 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 * @since 6.1
* @see #CHECKPOINT_PROPERTY_NAME * @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 = 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()); private final Log logger = LogFactory.getLog(getClass());
@ -182,6 +192,9 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
if (checkpointOnRefresh) { if (checkpointOnRefresh) {
new CracDelegate().checkpointRestore(); new CracDelegate().checkpointRestore();
} }
if (exitOnRefresh) {
Runtime.getRuntime().halt(0);
}
this.stoppedBeans = null; this.stoppedBeans = null;
try { try {

Loading…
Cancel
Save