Spring Batch не завершается при использовании Spring Integration JAR - PullRequest
0 голосов
/ 03 сентября 2018

Когда я использую Spring интеграции JAR, мое приложение Spring не завершается. MBeanExporter не отменяет регистрацию компонентов и завершает работу.

Вот журналы:

без баночки

2018-09-03 11:03:45 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]
2018-09-03 11:03:45 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - ResetRegressionDataBatchJob exiting with status of exitCode=COMPLETED;exitDescription=
2018-09-03 11:03:45 INFO  [Thread-118] o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@c6f9085f: startup date [Mon Sep 03 11:02:56 BST 2018]; root of context hierarchy
2018-09-03 11:03:45 INFO  [Thread-118] o.s.jmx.export.MBeanExporter - Unregistering JMX-exposed beans on shutdown
2018-09-03 11:03:45 INFO  [Thread-118] o.s.jmx.export.MBeanExporter - Unregistering JMX-exposed beans
2018-09-03 11:03:45 INFO  [Thread-118] o.s.s.c.ThreadPoolTaskExecutor - Shutting down ExecutorService 'taskExecutor'
2018-09-03 11:03:46 INFO  [Thread-118] o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'

С JAR

2018-09-03 11:06:55 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - Started ResetRegressionDataBatchJob in 50.735 seconds (JVM running for 51.906)
2018-09-03 11:06:55 INFO  [main] c.p.c.i.batch.BaseRunnableBatchJob - **************** jobShouldBeRun: True (Default - No Override)
2018-09-03 11:06:55 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] launched with the following parameters: [{}]
2018-09-03 11:06:55 INFO  [main] o.s.batch.core.job.SimpleStepHandler - Executing step: [step1]
2018-09-03 11:06:55 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - Running the Delete and Update Script for the Regression Reset Batch Job....
2018-09-03 11:06:55 INFO  [main] o.s.jdbc.datasource.init.ScriptUtils - Executing SQL script from class path resource [regression/data/regression.reset.deleteupdatedata.sql]
2018-09-03 11:06:55 INFO  [main] o.s.jdbc.datasource.init.ScriptUtils - Executed SQL script from class path resource [regression/data/regression.reset.deleteupdatedata.sql] in 193 ms.
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Start Time is 2018-09-03 11:06:55:282
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - End Time is 2018-09-03 11:06:55:528
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Duration 0:0:0.246
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Batch Status is COMPLETED
2018-09-03 11:06:55 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Exit Status is exitCode=COMPLETED;exitDescription=
2018-09-03 11:06:55 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]
2018-09-03 11:06:55 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - ResetRegressionDataBatchJob exiting with status of exitCode=COMPLETED;exitDescription=

С System.exit (0)

2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Start Time is 2018-09-03 11:49:50:052
2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - End Time is 2018-09-03 11:49:50:342
2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Duration 0:0:0.290
2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Batch Status is COMPLETED
2018-09-03 11:49:50 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Exit Status is exitCode=COMPLETED;exitDescription=
2018-09-03 11:49:50 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]
2018-09-03 11:49:50 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - ResetRegressionDataBatchJob exiting with status of exitCode=COMPLETED;exitDescription=
2018-09-03 11:49:50 INFO  [Thread-118] o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@fb5a33e4: startup date [Mon Sep 03 11:48:56 BST 2018]; root of context hierarchy
2018-09-03 11:49:50 INFO  [Thread-118] c.p.c.f.batch.ContextClosedHandler - Inside onApplicationEvent Shutting down ThreadPoolTaskExecutor
2018-09-03 11:49:50 INFO  [Thread-118] o.s.s.c.ThreadPoolTaskExecutor - Shutting down ExecutorService 'taskExecutor'
2018-09-03 11:49:50 INFO  [Thread-118] o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase 0
2018-09-03 11:49:50 INFO  [Thread-118] o.s.i.endpoint.EventDrivenConsumer - Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2018-09-03 11:49:50 INFO  [Thread-118] o.s.i.c.PublishSubscribeChannel - Channel 'application.errorChannel' has 0 subscriber(s).
2018-09-03 11:49:50 INFO  [Thread-118] o.s.i.endpoint.EventDrivenConsumer - stopped _org.springframework.integration.errorLogger
2018-09-03 11:49:50 INFO  [Thread-118] o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase -2147483648
2018-09-03 11:49:50 INFO  [Thread-118] o.s.jmx.export.MBeanExporter - Unregistering JMX-exposed beans on shutdown
2018-09-03 11:49:50 INFO  [Thread-118] o.s.jmx.export.MBeanExporter - Unregistering JMX-exposed beans
2018-09-03 11:49:50 INFO  [Thread-118] o.s.s.c.ThreadPoolTaskExecutor - Shutting down ExecutorService 'taskExecutor'
2018-09-03 11:49:51 INFO  [Thread-118] o.s.o.j.LocalContainerEntityManagerFactoryBean - Closing JPA EntityManagerFactory for persistence unit 'default'
2018-09-03 11:49:51 INFO  [Thread-118] o.s.s.c.ThreadPoolTaskScheduler - Shutting down ExecutorService 'taskScheduler'

С context.stop ()

2018-09-03 14:49:39 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - Started ResetRegressionDataBatchJob in 49.884 seconds (JVM running for 50.91)
2018-09-03 14:49:39 INFO  [main] o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase -2147483648
2018-09-03 14:49:39 INFO  [main] o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 0
2018-09-03 14:49:39 INFO  [main] c.p.c.i.batch.BaseRunnableBatchJob - **************** jobShouldBeRun: True (Default - No Override)
2018-09-03 14:49:39 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] launched with the following parameters: [{}]
2018-09-03 14:49:39 INFO  [main] o.s.batch.core.job.SimpleStepHandler - Executing step: [step1]
2018-09-03 14:49:39 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - Running the Delete and Update Script for the Regression Reset Batch Job....
2018-09-03 14:49:39 INFO  [main] o.s.jdbc.datasource.init.ScriptUtils - Executing SQL script from class path resource [regression/data/regression.reset.deleteupdatedata.sql]
2018-09-03 14:49:39 INFO  [main] o.s.jdbc.datasource.init.ScriptUtils - Executed SQL script from class path resource [regression/data/regression.reset.deleteupdatedata.sql] in 181 ms.
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Start Time is 2018-09-03 14:49:39:363
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - End Time is 2018-09-03 14:49:39:594
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Duration 0:0:0.231
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Batch Status is COMPLETED
2018-09-03 14:49:39 INFO  [main] c.p.c.i.b.l.BaseBatchListenerSupport - Exit Status is exitCode=COMPLETED;exitDescription=
2018-09-03 14:49:39 INFO  [main] o.s.b.c.l.support.SimpleJobLauncher - Job: [SimpleJob: [name=resetRegressionDataJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]
2018-09-03 14:49:39 INFO  [main] c.p.c.r.ResetRegressionDataBatchJob - ResetRegressionDataBatchJob exiting with status of exitCode=COMPLETED;exitDescription=
2018-09-03 14:49:39 INFO  [main] o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase 0
2018-09-03 14:49:39 INFO  [main] o.s.i.endpoint.EventDrivenConsumer - Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2018-09-03 14:49:39 INFO  [main] o.s.i.c.PublishSubscribeChannel - Channel 'application.errorChannel' has 0 subscriber(s).
2018-09-03 14:49:39 INFO  [main] o.s.i.endpoint.EventDrivenConsumer - stopped _org.springframework.integration.errorLogger
2018-09-03 14:49:39 INFO  [main] o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase -2147483648

Весенняя пусковая установка класса

public static void main(String [] args)  throws Exception{
        logger.info("Starting Regression Data Reset Batch job......");
        SpringApplication app = new SpringApplication(ResetRegressionDataBatchJob.class);
        app.setWebEnvironment(false);
        app.setBannerMode(Banner.Mode.OFF);
        ExitStatus exitStatus = app.run(args).getBean("resetRegressionDataBatchJob", ResetRegressionDataBatchJob.class).run(args);
        logger.info("ResetRegressionDataBatchJob exiting with status of "+exitStatus);
        if (!ExitStatus.COMPLETED.equals(exitStatus) && !ExitStatus.NOOP.equals(exitStatus))
            System.exit(-1);

    }

Я обновил журналы после добавления System.exit(0) и ctx.stop(). context.stop() не закрывает все компоненты, как System.exit(0). Поток еще работал, когда я использовал ctx.stop()

1 Ответ

0 голосов
/ 04 сентября 2018

Когда вы используете Spring Integration, он создает несколько активных компонентов в качестве компонентов инфраструктуры для поддержки других компонентов в контексте приложения. Одним из них является ThreadPoolTaskExecutor.

Чтобы правильно закрыть контекст приложения с активными компонентами, вам нужно использовать ConfigurableApplicationContext.close():

/**
 * Close this application context, releasing all resources and locks that the
 * implementation might hold. This includes destroying all cached singleton beans.
 * <p>Note: Does <i>not</i> invoke {@code close} on a parent context;
 * parent contexts have their own, independent lifecycle.
 * <p>This method can be called multiple times without side effects: Subsequent
 * {@code close} calls on an already closed context will be ignored.
 */
@Override
void close();

stop() не деактивирует активные компоненты, а только останавливает выполняемые в данный момент задачи и не позволяет запускать новые до тех пор, пока start() не вернется в контекст приложения или этого активного компонента.

...