Skip to content

Commit eb3982b

Browse files
committed
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
1 parent 258f99a commit eb3982b

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,22 +73,32 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
7373
/**
7474
* Property name for a common context checkpoint: {@value}.
7575
* @since 6.1
76-
* @see #CHECKPOINT_ON_REFRESH_VALUE
76+
* @see #ON_REFRESH_VALUE
7777
* @see org.crac.Core#checkpointRestore()
7878
*/
7979
public static final String CHECKPOINT_PROPERTY_NAME = "spring.context.checkpoint";
8080

8181
/**
82-
* Recognized value for the context checkpoint property: {@value}.
82+
* Property name for terminating the JVM when the context reaches a specific phase: {@value}.
83+
* @since 6.1
84+
* @see #ON_REFRESH_VALUE
85+
*/
86+
public static final String EXIT_PROPERTY_NAME = "spring.context.exit";
87+
88+
/**
89+
* Recognized value for the context checkpoint and exit properties: {@value}.
8390
* @since 6.1
8491
* @see #CHECKPOINT_PROPERTY_NAME
85-
* @see org.crac.Core#checkpointRestore()
92+
* @see #EXIT_PROPERTY_NAME
8693
*/
87-
public static final String CHECKPOINT_ON_REFRESH_VALUE = "onRefresh";
94+
public static final String ON_REFRESH_VALUE = "onRefresh";
8895

8996

9097
private static final boolean checkpointOnRefresh =
91-
CHECKPOINT_ON_REFRESH_VALUE.equalsIgnoreCase(SpringProperties.getProperty(CHECKPOINT_PROPERTY_NAME));
98+
ON_REFRESH_VALUE.equalsIgnoreCase(SpringProperties.getProperty(CHECKPOINT_PROPERTY_NAME));
99+
100+
private static final boolean exitOnRefresh =
101+
ON_REFRESH_VALUE.equalsIgnoreCase(SpringProperties.getProperty(EXIT_PROPERTY_NAME));
92102

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

@@ -182,6 +192,9 @@ public void onRefresh() {
182192
if (checkpointOnRefresh) {
183193
new CracDelegate().checkpointRestore();
184194
}
195+
if (exitOnRefresh) {
196+
Runtime.getRuntime().halt(0);
197+
}
185198

186199
this.stoppedBeans = null;
187200
try {

0 commit comments

Comments
 (0)