サイトアイコン たーちゃんの「ゼロよりはいくらかましな」

【jbatch】step-partitioningでListenerはいつ実施される?

 

前回に引き続き、jbatchものを1つ。

step-partitioningにおいて、Listener定義すると、

一体いつ実行されるのでしょう。

全体で1回なのか、それともpartitionごとに1回なのか。

早速、動かして確認してみましょう。

バッチのjob.xml定義

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<job id="tarchan-sample-job" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
     <!-- これを追加 -->
	<listeners>
		<listener ref="TestJobListener"></listener>
	</listeners>

	<step id="batch-001">
		<batchlet ref="SampleBatchlet">
			<properties>
				<property name="param" value="#{partitionPlan['param']}"/>
			</properties>
		</batchlet>

		<partition>
			<reducer ref="TestReducer" />
			<mapper ref="TestMapper" />
			<collector ref="TestCollector" />
			<analyzer ref="TestAnalyzer" />
		</partition>

	</step>

</job>

 

 

 

 

 

Listener

Listenerは標準出力で各処理の開始を知らせるのみの実装です。

package jp.co.tarchan.sample_javaee_webapp.batchlet;

import javax.batch.api.listener.JobListener;
import javax.enterprise.context.Dependent;
import javax.inject.Named;

@Dependent
@Named("TestJobListener")
public class TestJobListener implements JobListener {

    @Override
    public void beforeJob() throws Exception {
        System.out.println("Listener beforeJob start");
    }

    @Override
    public void afterJob() throws Exception {
        System.out.println("Listener afterJob start");
    }
}

 

いざ!

Listener以外のファイルは前回同様です。

 

動作させると以下のようになりました。

 

2019-02-22 07:09:38,891 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 74) コンテキスト '/sample-javaee-webapp-1.0.0' の Mojarra 2.3.5.SP2 を初期化します
2019-02-22 07:09:39,814 WARN  [io.jaegertracing.internal.senders.SenderResolver] (ServerService Thread Pool -- 74) No suitable sender found. Using NoopSender, meaning that data will not be sent anywhere!
2019-02-22 07:09:39,864 INFO  [io.jaegertracing.Configuration] (ServerService Thread Pool -- 74) Initialized tracer=JaegerTracer(version=Java-0.30.6, serviceName=sample-javaee-webapp-1.0.0.war, reporter=RemoteReporter(sender=NoopSender(), closeEnqueueTimeout=1000), sampler=RemoteControlledSampler(maxOperations=2000, manager=HttpSamplingManager(hostPort=localhost:5778), sampler=ProbabilisticSampler(tags={sampler.type=probabilistic, sampler.param=0.001})), tags={hostname=TakashiPC, jaeger.version=Java-0.30.6, ip=192.168.10.7}, zipkinSharedRpcSpan=false, expandExceptionLogs=false)
2019-02-22 07:09:39,903 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 74) WFLYUT0021: Registered web context: '/sample-javaee-webapp-1.0.0' for server 'default-server'
2019-02-22 07:09:39,932 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 42) WFLYSRV0010: Deployed "sample-javaee-webapp-1.0.0.war" (runtime-name : "sample-javaee-webapp-1.0.0.war")
2019-02-22 07:09:40,027 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
2019-02-22 07:09:40,031 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
2019-02-22 07:09:40,031 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
2019-02-22 07:09:40,031 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 14.0.1.Final (WildFly Core 6.0.2.Final) started in 26042ms - Started 465 of 637 services (327 services are lazy, passive or on-demand)
2019-02-22 07:09:44,653 INFO  [stdout] (Batch Thread - 1) Listener beforeJob start

2019-02-22 07:09:44,668 INFO  [stdout] (Batch Thread - 1) Mapper mapPartitions Start

2019-02-22 07:09:44,715 INFO  [stdout] (Batch Thread - 2) SampleBatchlet process start

2019-02-22 07:09:44,716 INFO  [stdout] (Batch Thread - 3) SampleBatchlet process start

2019-02-22 07:09:44,946 INFO  [stdout] (Batch Thread - 3) Collector collectPartitionData Start

2019-02-22 07:09:44,946 INFO  [stdout] (Batch Thread - 2) Collector collectPartitionData Start

2019-02-22 07:09:44,946 INFO  [stdout] (Batch Thread - 1) Analyzer analyzeCollectorData Start

2019-02-22 07:09:44,947 INFO  [stdout] (Batch Thread - 1) Analyzer analyzeCollectorData Start

2019-02-22 07:09:44,948 INFO  [stdout] (Batch Thread - 1) Analyzer analyzeStatus Start

2019-02-22 07:09:44,948 INFO  [stdout] (Batch Thread - 1) Analyzer analyzeStatus Start

2019-02-22 07:09:44,953 INFO  [stdout] (Batch Thread - 1) Listener afterJob start

 

このログのL10、L30をみると、

Listenerはバッチ全体として1回のようです。

 

 

まとめ

Lintenerは全体として1回、処理前・処理後の処理が

実行されるようです。

確かに、xmlの定義位置から鑑みても

各partitionごとなら個別に設定させる設計となりそうですしね。

 


にほんブログ村


人気ブログランキング

モバイルバージョンを終了