Skip to content

Commit 2b29dcb

Browse files
committed
Make JFR optional to support minimized JREs without jdk.jfr module
TaskExecutorJobOperator.start() creates a JobLaunchEvent which extends jdk.jfr.Event. On minimized JREs without the jdk.jfr module, this causes NoClassDefFoundError: jdk/jfr/Event. This commit wraps the JFR event creation in a try-catch block to handle the case when JFR is not available, allowing Spring Batch to work on minimized JREs without JFR support. Fixes #5326 Signed-off-by: Nikita Nagar <permanayan84@gmail.com>
1 parent 258da33 commit 2b29dcb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/TaskExecutorJobOperator.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,17 @@ public JobExecution start(Job job, JobParameters jobParameters) throws JobInstan
109109
JobExecutionAlreadyRunningException, JobRestartException, InvalidJobParametersException {
110110
Assert.notNull(job, "Job must not be null");
111111
Assert.notNull(jobParameters, "JobParameters must not be null");
112-
new JobLaunchEvent(job.getName(), jobParameters.toString()).commit();
112+
try {
113+
new JobLaunchEvent(job.getName(), jobParameters.toString()).commit();
114+
}
115+
catch (NoClassDefFoundError e) {
116+
// JFR is not available on this runtime (e.g., minimized JRE without jdk.jfr
117+
// module)
118+
// Silently ignore and continue without JFR events
119+
if (logger.isDebugEnabled()) {
120+
logger.debug("JFR is not available, skipping JFR event creation");
121+
}
122+
}
113123
Observation observation = MicrometerMetrics
114124
.createObservation(METRICS_PREFIX + "job.launch.count", this.observationRegistry)
115125
.start();

0 commit comments

Comments
 (0)