Spring Batch Job不进入STOPPED状态,应用程序永不退出

时间:2019-02-13 20:27:28

标签: spring-batch

我有一个从the documentation创建的Spring批处理作业。

应用程序永不退出。作业位于状态为STATUS = STOPPING,EXIT_CODE = COMPLETED的存储库中。

我希望作业的状态为已停止。通过添加System.exit()退出应用程序是否合适?

我在afterJob()侦听器中添加了日志记录,它记录了唯一步骤的状态为COMPLETED,并且步骤出口状态也为COMPLETED。有趣的是,jobExecution的作业状态也为COMPLETED,但是随后从SimpleJobLauncher进行的默认日志记录将记录状态为STOPPING。

Spring Batch starter 2.1.2发布

编辑:

  

[BatchJobCompletionNotificationListener] !!!工作已完成!

     

[BatchJobCompletionNotificationListener]作业不再以状态[STOPPING]退出状态[exitCode = COMPLETED; exitDescription =]运行。

     

[BatchJobCompletionNotificationListener]步骤[step1]状态[COMPLETED]退出状态[exitCode = COMPLETED; exitDescription =]。

     

[SimpleJobLauncher]作业:[FlowJob:[name = myjob]]使用以下参数完成:[{run.id = 62,-spring.config.location = application.yaml}]和以下状态:[正在停止] ]

这就是我的日志记录的结​​尾。

不确定是否应该有所作为,但是我正在将JdbcPagingItemReader与PagingQueryProvider一起使用(基于this example

1 个答案:

答案 0 :(得分:0)

只需尝试使用引导2.1.2RLEASE入门指南,它就会按预期工作:

# mbenhassine @ localhost in /tmp [9:57:11]
$ git clone https://github.com/spring-guides/gs-batch-processing
Cloning into 'gs-batch-processing'...
remote: Enumerating objects: 1121, done.
remote: Total 1121 (delta 0), reused 0 (delta 0), pack-reused 1121
Receiving objects: 100% (1121/1121), 448.58 KiB | 205.00 KiB/s, done.
Resolving deltas: 100% (682/682), done.

# mbenhassine @ localhost in /tmp [9:57:35]
$ cd gs-batch-processing/complete

# mbenhassine @ localhost in /tmp/gs-batch-processing/complete on git:master o [9:57:45]
$ vim pom.xml

# mbenhassine @ localhost in /tmp/gs-batch-processing/complete on git:master x [9:58:16]
$ cat pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.springframework</groupId>
    <artifactId>gs-batch-processing</artifactId>
    <version>0.1.0</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.2.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-batch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

# mbenhassine @ localhost in /tmp/gs-batch-processing/complete on git:master x [9:58:22]
$ mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gs-batch-processing 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ gs-batch-processing ---
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ gs-batch-processing ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ gs-batch-processing ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to /private/tmp/gs-batch-processing/complete/target/classes
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ gs-batch-processing ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /private/tmp/gs-batch-processing/complete/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ gs-batch-processing ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.22.1:test (default-test) @ gs-batch-processing ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:3.1.1:jar (default-jar) @ gs-batch-processing ---
[INFO] Building jar: /private/tmp/gs-batch-processing/complete/target/gs-batch-processing-0.1.0.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.1.2.RELEASE:repackage (repackage) @ gs-batch-processing ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.558 s
[INFO] Finished at: 2019-02-27T09:58:36+01:00
[INFO] Final Memory: 25M/94M
[INFO] ------------------------------------------------------------------------

# mbenhassine @ localhost in /tmp/gs-batch-processing/complete on git:master x [9:58:36]
$ java -jar target/gs-batch-processing-0.1.0.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.2.RELEASE)

2019-02-27 09:58:47.669  INFO 85483 --- [           main] hello.Application                        : Starting Application v0.1.0 on localhost with PID 85483 (/private/tmp/gs-batch-processing/complete/target/gs-batch-processing-0.1.0.jar started by mbenhassine in /private/tmp/gs-batch-processing/complete)
2019-02-27 09:58:47.672  INFO 85483 --- [           main] hello.Application                        : No active profile set, falling back to default profiles: default
2019-02-27 09:58:48.491  INFO 85483 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-02-27 09:58:48.497  WARN 85483 --- [           main] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=org.hsqldb.jdbcDriver was not found, trying direct instantiation.
2019-02-27 09:58:48.781  INFO 85483 --- [           main] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Driver does not support get/set network timeout for connections. (feature not supported)
2019-02-27 09:58:48.785  INFO 85483 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2019-02-27 09:58:49.137  INFO 85483 --- [           main] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: HSQL
2019-02-27 09:58:49.298  INFO 85483 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
2019-02-27 09:58:49.446  INFO 85483 --- [           main] hello.Application                        : Started Application in 2.117 seconds (JVM running for 2.528)
2019-02-27 09:58:49.448  INFO 85483 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: []
2019-02-27 09:58:49.532  INFO 85483 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=importUserJob]] launched with the following parameters: [{run.id=1}]
2019-02-27 09:58:49.559  INFO 85483 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
2019-02-27 09:58:49.646  INFO 85483 --- [           main] hello.PersonItemProcessor                : Converting (firstName: Jill, lastName: Doe) into (firstName: JILL, lastName: DOE)
2019-02-27 09:58:49.646  INFO 85483 --- [           main] hello.PersonItemProcessor                : Converting (firstName: Joe, lastName: Doe) into (firstName: JOE, lastName: DOE)
2019-02-27 09:58:49.646  INFO 85483 --- [           main] hello.PersonItemProcessor                : Converting (firstName: Justin, lastName: Doe) into (firstName: JUSTIN, lastName: DOE)
2019-02-27 09:58:49.646  INFO 85483 --- [           main] hello.PersonItemProcessor                : Converting (firstName: Jane, lastName: Doe) into (firstName: JANE, lastName: DOE)
2019-02-27 09:58:49.646  INFO 85483 --- [           main] hello.PersonItemProcessor                : Converting (firstName: John, lastName: Doe) into (firstName: JOHN, lastName: DOE)
2019-02-27 09:58:49.658  INFO 85483 --- [           main] hello.JobCompletionNotificationListener  : !!! JOB FINISHED! Time to verify the results
2019-02-27 09:58:49.661  INFO 85483 --- [           main] hello.JobCompletionNotificationListener  : Found <firstName: JILL, lastName: DOE> in the database.
2019-02-27 09:58:49.661  INFO 85483 --- [           main] hello.JobCompletionNotificationListener  : Found <firstName: JOE, lastName: DOE> in the database.
2019-02-27 09:58:49.661  INFO 85483 --- [           main] hello.JobCompletionNotificationListener  : Found <firstName: JUSTIN, lastName: DOE> in the database.
2019-02-27 09:58:49.661  INFO 85483 --- [           main] hello.JobCompletionNotificationListener  : Found <firstName: JANE, lastName: DOE> in the database.
2019-02-27 09:58:49.662  INFO 85483 --- [           main] hello.JobCompletionNotificationListener  : Found <firstName: JOHN, lastName: DOE> in the database.
2019-02-27 09:58:49.664  INFO 85483 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=importUserJob]] completed with the following parameters: [{run.id=1}] and the following status: [COMPLETED]
2019-02-27 09:58:49.668  INFO 85483 --- [       Thread-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2019-02-27 09:58:49.673  INFO 85483 --- [       Thread-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

# mbenhassine @ localhost in /tmp/gs-batch-processing/complete on git:master x [9:58:49]
$
  

通过添加System.exit()退出应用程序是否合适?

否,您应该正常关闭应用程序以正确释放任何资源并避免资源泄漏。

相关问题