You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BasicBatchConfigurer.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/BatchConfigurerConfiguration.java
+10-5
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2012-2019 the original author or authors.
2
+
* Copyright 2012-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/batch/JpaBatchConfigurer.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/BatchAutoConfigurationTests.java
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/batch/JobLauncherApplicationRunnerTests.java
+2-2
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
/*
2
-
* Copyright 2012-2021 the original author or authors.
2
+
* Copyright 2012-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -223,7 +223,7 @@ static class BatchConfiguration extends BasicBatchConfigurer {
Copy file name to clipboardExpand all lines: spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/batch.adoc
+30
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,19 @@
3
3
A number of questions often arise when people use Spring Batch from within a Spring Boot application.
4
4
This section addresses those questions.
5
5
6
+
[[howto.batch.architectural-considerations]]
7
+
=== Architectural Considerations
8
+
9
+
The default configuration of Spring Batch is geared towards single-job containerized Spring Boot apps orchestrated by a job scheduler like Kubernetes, optionally using https://dataflow.spring.io/[Spring Cloud Dataflow]:
10
+
11
+
* All `Jobs` in the application context are executed once on application startup; see <<#howto.batch.running-jobs-on-startup>>.
12
+
* Jobs are run on the same thread they are launched on.
13
+
14
+
However, it is also a valid option to run batch jobs as part of other applications, notably web applications running in servlet containers.
15
+
Example use cases include reporting, ad-hoc job running, and web application support.
16
+
See {spring-batch-docs}job.html#runningJobsFromWebContainer[the Spring Batch documentation] for how to do this.
17
+
You might need to <<#howto.batch.customizing-task-executor,customize the task executor for batch jobs>> if you opt for this approach.
18
+
6
19
7
20
8
21
[[howto.batch.specifying-a-data-source]]
@@ -57,3 +70,20 @@ This provides only one argument to the batch job: `someParameter=someValue`.
57
70
Spring Batch requires a data store for the `Job` repository.
58
71
If you use Spring Boot, you must use an actual database.
59
72
Note that it can be an in-memory database, see {spring-batch-docs}job.html#configuringJobRepository[Configuring a Job Repository].
73
+
74
+
[[howto.batch.customizing-task-executor]]
75
+
=== Customizing the TaskExecutor for Batch Jobs
76
+
77
+
By default, jobs are run on the same thread they are launched on.
78
+
See {spring-batch-api}/core/configuration/annotation/EnableBatchProcessing.html[the Javadoc of `@EnableBatchProcessing`] for details.
79
+
Depending on your type of application, this might be undesirable because the starting thread is blocked while the batch job runs.
80
+
Furthermore, additional jobs might have to wait for the currently running job to complete.
81
+
In such a case, it is necessary to customize the `TaskExecutor` used by Spring Batch.
82
+
The auto-configuration of Spring Batch automatically picks up any `TaskExecutor` annotated with `@BatchTaskExecutor`, for example:
The example configures a `TaskExecutor` that dynamically adapts it size and uses up to 4 threads with a maximum queue size of 10. Adjust this configuration to match the needs of your application.
0 commit comments