Spring Batch Job не переходит в состояние STOPPED, приложение никогда не завершается - PullRequest
0 голосов
/ 13 февраля 2019

У меня есть пакетное задание Spring, созданное из документации .

Приложение никогда не завершается.Задание находится в хранилище с STATUS = STOPPING, EXIT_CODE = COMPLETED.

Я ожидаю, что задание будет иметь статус STOPPED.Является ли подходящим способом выхода из приложения путем добавления System.exit ()?

Я добавил запись в прослушивателе afterJob (), и он отмечает состояние единственного шага как выполненного с состоянием выхода шага как выполненного какЧто ж.Интересно, что задание JobExecution также имеет статус ЗАВЕРШЕНО, но запись по умолчанию из SimpleJobLauncher впоследствии регистрирует состояние STOPPING.

Spring Batch starter 2.1.2.RELEASE

РЕДАКТИРОВАТЬ:

[BatchJobCompletionNotificationListener] !!!ЗАДАНИЕ ЗАВЕРШЕНО!

[BatchJobCompletionNotificationListener] Задание больше не выполняется со статусом [STOPPING] состояние выхода [exitCode = COMPLETED; exitDescription =].

[BatchJobCompletionNotificationListener] Шаг [шаг1] статус [ЗАВЕРШЕНО]status [exitCode = COMPLETED; exitDescription =].

[SimpleJobLauncher] Задание: [FlowJob: [name = myjob]] завершено со следующими параметрами: [{run.id = 62, -spring.config.location= application.yaml}] и следующий статус: [STOPPING]

Это конец моей регистрации.

Не уверен, что это должно иметь значение, но яиспользование JdbcPagingItemReader с PagingQueryProvider (на основе этот пример

1 Ответ

0 голосов
/ 27 февраля 2019

Только что попробовал руководство по началу работы с загрузкой 2.1.2.RLEASE, и оно работает как положено:

# 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 ()?

Нет, вам следует корректно завершить работу приложения, чтобы правильно освободить любой ресурс и избежать утечки ресурса.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...