104
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 1

1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 1

Page 2: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 2

Batch Application for the Java Platform – JSR352

NTTコムウェア株式会社 技術SE部 OSS・AP技術 担当 上妻 宜人

Page 3: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 3

自己紹介

上妻 宜人 (あげつま のりと)

NTTコムウェア株式会社 勤務

社内のJava/APサーバの技術サポートを担当しています

Page 4: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 4

バッチってなんだろう?

Page 5: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 5

月次締め 処理

銀行 勘定システム

在庫管理

深夜に起動(非対話型) 計算量が多い

ジョブ 順序制御 並列実行

Page 6: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 6

月次締め 処理

銀行 勘定システム

在庫管理

深夜に起動(非対話型) 計算量が多い

ジョブ 順序制御 並列実行

多くの業種にバッチ処理 (会計 金融 流通 …)

Page 7: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 7

月次締め 処理

銀行 勘定システム

在庫管理

深夜に起動(非対話型) 計算量が多い

ジョブ 順序制御 並列実行

業種は違えど、 処理の背景は同じ

Page 8: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 8

月次締め 処理

銀行 勘定システム

在庫管理

深夜に起動(非対話型) 計算量が多い

ジョブ 順序制御 並列実行

バッチに求められる機能も 業種をまたがって同じ

Page 9: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 9

異なる業種が

類似の処理の背景を持って、

同じような機能を作る

Page 10: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 10

D R Y !!! 同じことを何度も繰り返すべからず

Page 11: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 11

標準化しよう

IBM (Spec Lead)

Oracle (Expert Group Member)

RedHat (同)

VMWare(同)

Credit Suisse (同)

ユーザ企業によるJava貢献 http://mi9.com/get-together_232.html

Page 12: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 12

JSR352

Batch Application for

The Java Platform

Page 13: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 13

Portable

Extensions

JSP 2.2

Servlet 3.1

Concurrency

Utilities for EE

Batch

Applications

(JSR 352)

Java API for JSON

(JSR-353)

Java API for

WebSocket

(JSR-355)

JSP2.2 JSP2.2 CDI 1.1

Managed Beans 1.0 EJB 3.2

Connector

1.0 JPA 2.1 JTA 1.1 JMS 2.0

JSF 2.2 JAX-RS

2.0 EL 3.0

が Java EE 7 で新たに盛り込まれる仕様

jBatch は Java EE 7 へ

Page 14: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 14

正式な仕様名は (Batch Application for the java Platform)

とても長いので、

Page 15: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 15

ここからは jBatch で.

Page 16: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 16

Program Agenda

jBatch の概要

アーキテクチャ

– ユーザは何を実装するのか

– Chunk方式処理の流れ

Spring Batch との違い

Java SE / EE の違い

Page 17: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 17

jBatch の概要

Page 18: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 18

jBatch って何が仕様化されているの?

どんなことができるの?

Page 19: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 19

JobOperator Job Step

JobRepository

ItemReader

ItemProcessor

ItemWriter

1. バッチ用語と関連性の定義 (DSL)

2. ジョブXMLの定義

<job id="samplejob">

<step id="step1"/>

</job>

3. APIの定義

public interface ItemReader {

Object readItem(Object item);

}

jBatch仕様 3つの構成

Page 20: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 20

2. ジョブXMLの定義

<job id="samplejob">

<step id="step1"/>

</job>

3. APIの定義

public interface ItemReader {

Object readItem(Object item);

}

どのような構成で作るのか (アーキテクチャ定義)

jBatch仕様 3つの構成

JobOperator Job Step

JobRepository

ItemReader

ItemProcessor

ItemWriter

1. バッチ用語と関連性の定義 (DSL)

Page 21: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 21

2. ジョブXMLの定義

<job id="samplejob">

<step id="step1"/>

</job>

3. APIの定義

public interface ItemReader {

Object readItem(Object item);

}

jBatch仕様 3つの構成

JobOperator Job Step

JobRepository

ItemReader

ItemProcessor

ItemWriter

1. バッチ用語と関連性の定義 (DSL)

アーキテクチャをどうやって 実装するか(XML/API 定義)

Page 22: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 22

jBatchの機能1 – 順序制御

ジョブXMLで処理の順序を定義することができる。

start

STEP1 Flow1

STEP2-1 STEP2-2

Flow(グループ化)

Decision(分岐)

STEP3-1

Split

Flow

Flow

Flow

end

Split(並行実行)

Page 23: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 23

jBatchの機能2 – チェックポイント

デフォルトでは10レコードごとにコミットされる。

commit

commit

10行処理 10行処理

×

障害発生

ロールバックは最終コミットまで

途中からリスタートも可能

Page 24: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 24

jBatchの機能3 – エラーハンドリング

jBatch

No. Message

001 I like GlassFish4.

002 I like Java EE 7.

999999999 Bad Record.

004 I like modern framework.

壊れたデータをスキップして処理を継続することができる。

success

Page 25: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 25

jBatchの機能3 – エラーハンドリング

jBatch

No. Message

001 I like GlassFish4.

002 I like Java EE 7.

999999999 Bad Record.

004 I like modern framework.

壊れたデータをスキップして処理を継続することができる。

success

Page 26: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 26

jBatchの機能3 – エラーハンドリング

jBatch

No. Message

001 I like GlassFish4.

002 I like Java EE 7.

999999999 Bad Record.

004 I like modern framework.

壊れたデータをスキップして処理を継続することができる。

Page 27: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 27

jBatchの機能3 – エラーハンドリング

jBatch

No. Message

001 I like GlassFish4.

002 I like Java EE 7.

999999999 Bad Record.

004 I like modern framework.

壊れたデータをスキップして処理を継続することができる。

error

Page 28: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 28

jBatchの機能3 – エラーハンドリング

jBatch

No. Message

001 I like GlassFish4.

002 I like Java EE 7.

999999999 Bad Record.

004 I like modern framework.

壊れたデータをスキップして処理を継続することができる。

SKIP

Page 29: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 29

jBatchの機能3 – エラーハンドリング

jBatch

No. Message

001 I like GlassFish4.

002 I like Java EE 7.

999999999 Bad Record.

004 I like modern framework.

壊れたデータをスキップして処理を継続することができる。

success

success

skip

success

Page 30: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 30

ジョブスケジューラ と jBatch

ジョブ実行順序管理 JP1: ジョブネット

jBatch : ジョブ定義XML

スケジューリング (時刻・周期起動)

実行権限の管理

ジョブ実装サポート (API/例外制御)

ジョブスケジューラ (cron/JP1/Tivoliなど) jBatch

Page 31: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 31

ジョブスケジューラ と jBatch

ジョブ実行順序管理 JP1: ジョブネット

スケジューリング (時刻・周期起動)

実行権限の管理

ジョブスケジューラ (cron/JP1/Tivoliなど)

Page 32: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 32

ジョブスケジューラ と jBatch

ジョブ実行順序管理 JP1: ジョブネット

jBatch : ジョブ定義XML

スケジューリング (時刻・周期起動)

実行権限の管理

ジョブ実装サポート (API/例外制御)

ジョブスケジューラ (cron/JP1/Tivoliなど) jBatch

Page 33: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 33

ジョブスケジューラ と jBatch

ジョブ実行順序管理 JP1: ジョブネット

jBatch : ジョブ定義XML

スケジューリング (時刻・周期起動)

実行権限の管理

ジョブ実装サポート (API/例外制御)

ジョブスケジューラ (cron/JP1/Tivoliなど) jBatch

jBatchはスケジューリング機能を持っていない。

Page 34: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 34

ジョブスケジューラ と jBatch

ジョブ実行順序管理 JP1: ジョブネット

jBatch : ジョブ定義XML

スケジューリング (時刻・周期起動)

実行権限の管理

ジョブ実装サポート (API/例外制御)

ジョブスケジューラ (cron/JP1/Tivoliなど) jBatch

被る部分は使い分け整理する必要がある。

Page 35: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 35

jBatchは バッチ処理の標準APIを提供します。

Page 36: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 36

jBatch の位置づけ

Cron

他の Java EE 仕様と同様に、APIを提供するのが役割

JA

X-R

S 2

.0

ユーザアプリケーション

jBatch

Java EE サーバ

CDI JTA

EJB/JPA …

データベース

ファイル (CSV/XML 等)

APIの利用

Page 37: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 37

jBatch を起動する

Cron

JA

X-R

S 2

.0

ユーザアプリケーション

jBatch

Java EE サーバ

CDI JTA

EJB/JPA …

データベース

ファイル (CSV/XML 等)

時刻起動

http post http://localhost:8080/batch/job/1

Page 38: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 38

jBatch を起動する

Cron

JA

X-R

S 2

.0

ユーザアプリケーション

jBatch

Java EE サーバ

CDI JTA

EJB/JPA …

データベース

ファイル (CSV/XML 等)

時刻起動

http post http://localhost:8080/batch/job/1 @Path("/jobs/{jobId}")

public class BatchResource {

@POST

public void start(@PathParam("jobId") String jobId) {

// バッチジョブの起動

JobOperator jobOperator = BatchRuntime.getJobOperator();

jobOperator.start(jobId, null);

}

}

Page 39: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 39

Java EE のコードから 簡単にバッチ起動が可能です。 (JAX-RS EJB Servlet など)

Page 40: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 40

アーキテクチャ

Page 41: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 41

アーキテクチャ

メインフレームのバッチの移行を視野に入れた構造

JCLやCOBOL開発者にも馴染みやすい

JobOperator

Step1 Step2 Step3

Item

Reader

Item

Processor

Item

Writer batchlet

Job

Job Repositoty

Page 42: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 42

ジョブ : トップレベル要素

ジョブは1つ以上のステップから構成

ステップ全体に関わる設定はジョブに設定

リスタート可能かどうか? ジョブ設定プロパティ 等

JobOperator

Step1 Step2 Step3

Item

Reader

Item

Processor

Item

Writer batchlet

Job

Job Repositoty

Page 43: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 43

ジョブ : トップレベル要素

ジョブは1つ以上のステップから構成

ステップ全体に関わる設定はジョブに設定

リスタート可能かどうか? ジョブ設定プロパティ 等

JobOperator

Step1 Step2 Step3

Item

Reader

Item

Processor

Item

Writer batchlet

Job

Job Repositoty

<job id="samplejob">

<step id="step1" next="step2" />

<step id="step2" />

<properties>

<property name="filePath" value="input.txt">

</properties>

</job>

Page 44: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 44

ジョブ : トップレベル要素

ジョブは1つ以上のステップから構成

ステップ全体に関わる設定はジョブに設定

リスタート可能かどうか? ジョブ設定プロパティ 等

JobOperator

Step1 Step2 Step3

Item

Reader

Item

Processor

Item

Writer batchlet

Job

Job Repositoty

<job id="samplejob">

<step id="step1" next="step2" />

<step id="step2" />

<properties>

<property name="filePath" value="input.txt">

</properties>

</job>

ジョブID. 必須属性. 一意の識別子を設定。

JobOperator.start(“samplejob”, null);

Page 45: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 45

ジョブ : トップレベル要素

ジョブは1つ以上のステップから構成

ステップ全体に関わる設定はジョブに設定

リスタート可能かどうか? ジョブ設定プロパティ 等

JobOperator

Step1 Step2 Step3

Item

Reader

Item

Processor

Item

Writer batchlet

Job

Job Repositoty

<job id="samplejob">

<step id="step1" next="step2" />

<step id="step2" />

<properties>

<property name="filePath" value="input.txt">

</properties>

</job>

ステップの流れを定義する。

最低1つ以上のステップが必要。

Page 46: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 46

ジョブ : トップレベル要素

ジョブは1つ以上のステップから構成

ステップ全体に関わる設定はジョブに設定

リスタート可能かどうか? ジョブ設定プロパティ 等

JobOperator

Step1 Step2 Step3

Item

Reader

Item

Processor

Item

Writer batchlet

Job

Job Repositoty

<job id="samplejob">

<step id="step1" next="step2" />

<step id="step2" />

<properties>

<property name="filePath" value="input.txt">

</properties>

</job>

ジョブ全体で使うプロパティ。

オプション要素。

Page 47: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 47

ジョブインスタンスの考え方

スケジュールごとにJobInstanceが生成される

実行ごとにJobExecutionが生成される

JobInstanceは再実行に備えて永続化 (シリアライズ)

Job

JobInstance JobInstance

JobInstance JobExecution

『ファイル取り込み』 ジョブ

2013/08/22 に実行する 『ファイル取り込み』 ジョブ

2013/08/22 に実行する 『ファイル取り込み』 ジョブの1回目

Page 48: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 48

ジョブインスタンスが永続化される訳

8/22 のジョブインタンスは、8/23 に再実行しても、 8/22 のデータにアクセスする。

対象データが異なる場合は、前日リスタート分と 当日分のジョブを並行処理させることも可能。

JobInstance

8月22日分のジョブ

JobExecution JobExecution

Date Sales amount

8/22 ¥30, 000

8/22 ¥30, 000

8/23 ¥30, 000

8/22 1回目の実行(失敗)

8/23 8/22分リスタート

再開時も8/22分の データを処理

Page 49: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 49

各ステップの処理内容はユーザがコーディングする

ステップの実装方法

– chunk方式 : reader processor writer の実装

– batchlet方式 : batchletインタフェース のみ実装

JobOperator Step1 Step2 Step3

Item

Reader

Item

Processor

Item

Writer batchlet

Job

Job Repositoty

ステップ : ジョブに含まれるタスク

Page 50: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 50

chunk方式の登場人物

Step ItemReader ItemProcessor ItemWriter

Page 51: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 51

ItemReader 実装方法

Step ItemReader ItemProcessor ItemWriter

@Named

public class MyReader implements ItemReader {

@Override

public void open(Serializable checkPoint)

throws Exception {..}

@Override

public Object readItem() throws Exception {..}

@Override

public void close() throws Exception {..}

...

}

Page 52: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 52

ItemProcessor 実装方法

Step ItemReader ItemWriter

@Named

public class MyProcessor implements ItemProcessor {

@Override

public Object processItem(Object item)

throws Exception {..}

}

ItemProcessor

Page 53: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 53

ItemWriter 実装方法

Step ItemReader

@Named

public class MyWriter implements ItemWriter {

@Override

public void open(Serializable checkPoint)

throws Exception {..}

@Override

public Object writeItems(List<Object> items)

throws Exception {..}

@Override

public void close() throws Exception {..}

...

}

ItemWriter ItemProcessor

Page 54: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 54

まずはオープンする

Step ItemReader ItemProcessor ItemWriter

Open

Open

Page 55: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 55

アイテムを1件読む

Step ItemReader ItemProcessor ItemWriter

Open

Open

readItem

Page 56: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 56

アイテムを1件処理する

Step ItemReader ItemProcessor ItemWriter

Open

Open

readItem

processItem(item)

Page 57: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 57

次の1件を読みに行く

Step ItemReader ItemProcessor ItemWriter

readItem

Page 58: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 58

同じく1件処理する

Step ItemReader ItemProcessor ItemWriter

readItem

processItem(item)

Page 59: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 59

また読み込みを処理を行う。

Step ItemReader ItemProcessor ItemWriter

readItem

processItem(item)

readItem

processItem(item)

Page 60: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 60

デフォルトでは10回、読み込みと処理を繰り返す

Step ItemReader ItemProcessor ItemWriter

readItem

processItem(item)

readItem

processItem(item)

1アイテム目の

読み込みと処理

2アイテム目の

読み込みと処理

Page 61: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 61

10アイテム目の処理が終わると

Step ItemReader ItemProcessor ItemWriter

readItem

processItem(item)

10アイテム目の

読み込みと処理

Page 62: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 62

まとめて書き込み処理を行う

Step ItemReader ItemProcessor ItemWriter

readItem

processItem(item)

10アイテム目の

読み込みと処理

writeItems(results)

Page 63: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 63

chunk方式のゆえん

Step ItemReader ItemProcessor ItemWriter

readItem

processItem(item)

10個ずつ纏めて塊を処理しているので、 Chunk(塊)方式 と呼ばれる。

writeItems(results)

Page 64: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 64

書いたらcheckpointを実行

Step ItemReader ItemProcessor ItemWriter

readItem

processItem(item)

writeItems(results)

checkpointInfo

checkpointData

checkpointinfo

Chunkの書き出しが終わると、 コミット前にcheckpointinfoが実行される。

Page 65: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 65

checkpointInfoの実装

Step ItemReader ItemProcessor ItemWriter

readItem

processItem(item)

writeItems(results)

checkpointInfo

checkpointData

checkpointinfo

@Named

public class MyReader implements ItemReader {

@Override

public void open(Serializable checkPoint) throws Exception {..}

@Override

public Serializable checkpointInfo() throws Exception {

// 読み込んだ行数をチェックポイントにする return readedCount; // => 1

}

}

Page 66: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 66

チェックポイントは

リスタート時に使われる。

Page 67: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 67

スタートとリスタートは違う

// バッチジョブの起動 JobOperator jobOperator = BatchRuntime.getJobOperator();

long jobExecId = jobOperator.start(“myjob”, null);

// ジョブのリスタート long jobExecId = jobOperator.restart(jobExecId, null);

初回起動時はjob.xmlの <job id =“myjob”> のid文字列を指定する。

Page 68: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 68

スタートとリスタートは違う

// バッチジョブの起動 JobOperator jobOperator = BatchRuntime.getJobOperator();

long jobExecId = jobOperator.start(“myjob”, null);

// ジョブのリスタート long jobExecId = jobOperator.restart(jobExecId, null);

リスタートするときは restart で起動する。 初回起動時に取得したジョブ実行ID(long)を 引数に指定する。

Page 69: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 69

スタートとリスタートは違う

// バッチジョブの起動 JobOperator jobOperator = BatchRuntime.getJobOperator();

long jobExecId = jobOperator.start(“myjob”, null);

// ジョブのリスタート long jobExecId = jobOperator.restart(jobExecId, null);

restart で起動すると、 open(Serializable cp) に checkpointInfo()で返された値が渡される。 通常の start では、nullが常に渡される。

@Named

public class MyReader implements ItemReader {

@Override

public void open(Serializable checkPoint) throws Exception {..}

@Override

public Serializable checkpointInfo() throws Exception {

return readedCount; // => 1

}

Page 70: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 70

commitの実行

Step ItemReader ItemProcessor ItemWriter

readItem

processItem(item)

writeItems(results)

checkpointInfo

checkpointData

checkpointinfo

checkpoint処理が終わったら、 バッチランタイムで commit する。 (GlassFish であればJTAトランザクション)

commit

Page 71: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 71

chunk処理終了の流れ

Step ItemReader ItemProcessor ItemWriter

readItem

読み込み対象のデータがなくなった!

Page 72: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 72

chunk処理終了の流れ

Step ItemReader ItemProcessor ItemWriter

readItem

ItemReaderから null を返す。 null

Page 73: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 73

chunk処理終了の流れ

Step ItemReader ItemProcessor ItemWriter

readItem

処理済みのデータを書き出す。

null

writeItems(results)

Page 74: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 74

チェックポイントを実行する。

Step ItemReader ItemProcessor ItemWriter

readItem

null

writeItems(results)

checkpointInfo

checkpointData

checkpointinfo

Page 75: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 75

トランザクションをコミットする

Step ItemReader ItemProcessor ItemWriter

readItem

null

writeItems(results)

checkpointInfo

checkpointData

checkpointinfo

commit

Page 76: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 76

コミット後は close 処理を行う

Step ItemReader ItemProcessor ItemWriter

commit

close

close

ItemReaderとItemWriterのclose処理をして chunk方式のステップは完了。

Page 77: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 77

chunk方式 : job.xml の書き方

<?xml version="1.0" encoding="UTF-8"?>

<job xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0" id="job1">

<step>

<chunk item-count="100">

<reader ref="myReader"/>

<processor ref="myProcessor"/>

<writer ref="myWriter"/>

</chunk>

</step>

</job>

Page 78: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 78

chunk方式 : chunkタグとオプション

<?xml version="1.0" encoding="UTF-8"?>

<job xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0" id="job1">

<step>

<chunk item-count="100">

<reader ref="myReader"/>

<processor ref="myProcessor"/>

<writer ref="myWriter"/>

</chunk>

</step>

</job>

Stepの子要素としてchunkを定義。 コミット間隔チューニングは、item-count属性。 デフォルトは10。

Page 79: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 79

chunk方式 : reader/processor/writer

<?xml version="1.0" encoding="UTF-8"?>

<job xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0" id="job1">

<step>

<chunk item-count="100">

<reader ref="myReader"/>

<processor ref="myProcessor"/>

<writer ref="myWriter"/>

</chunk>

</step>

</job> ItemReader ItemProcessor ItemWriterの クラス名の先頭を小文字にして定義する。

Page 80: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 80

F A Q

全てのメソッドの

実装を強制されると困ります..

(open close処理が必要ない場合)

Page 81: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 81

空実装されたAbstractReaderを継承

デフォルト実装は空実装 (何もしない)

openやcloseが呼ばれても何もしない

public class MyReader extends AbstractItemReader {

@Override

public Object readItem() throws Exception {

// read処理の実装 }

}

Page 82: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 82

F A Q

Abstractクラスを使うと、

他クラスを継承できないので困る

(POJOが一番嬉しい..)

Page 83: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 83

Public Reviewフェーズまでは、

アノテーション活用提案があった。

Page 84: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 84

アノテーションでItemReaderが定義できた

@Named

public class MyItemReader {

@ReadItem

Object read() throws Exception {

// レコード読み取り処理 }

} 今後盛り込まれることを期待。

Page 85: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 85

F A Q

チャンク処理を実装することで、

何かメリットはあるのか?

Page 86: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 86

共通的な機能を自身で作成しなくてもよくなる

APサーバからコールバックすることで、以下の処理を差し込める

コミット間隔のコントロール

例外が発生したときのハンドリング

– 例外をスキップするのか

– 例外が発生した時点でバッチ処理を中断するのか

Page 87: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 87

処理したレコード数がモニタリング可能になる

GlassFish4の管理コンソールでは、jBatch状態の確認が可能。

Page 88: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 88

もう1つのStep実装方式 : batchlet

Step

Stepとbatchletが1対1。非常にシンプルな実装。

batchlet

process()

ExitStatus

public class MyBatchlet implements Batchlet {

@Override

public String process() throws Exception { // 処理をここに実装

}

@Override

public void stop() throws Exception { // JobOperator.stop()で強制停止した時の処理をここに実装

}

}

<step id="step1">

<batchlet ref="myBatchlet" />

</step>

Page 89: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 89

chunkとbatchletの使い分け

Chunk方式

– バルクオペレーション全般

– ファイル、DBレコードを1件ずつ処理

batchlet方式

– コマンド処理全般

– 他サーバへのファイル転送 (ftpなど)

– 圧縮 解凍コマンドの実行

Page 90: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 90

JobOperator

JobOperator Step1 Step2 Step3

Item

Reader

Item

Processor

Item

Writer batchlet

Job

Job Repositoty

バッチ処理のコントロール役

JobOperator経由でジョブ起動/再起動/停止

Page 91: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 91

JobRepository : 永続化機構

ジョブインスタンスやチェックポイント情報を保存

仕様上ではあまり詳細については言及されず

GlassFish4 同梱のRIでは組み込みDerbyに永続化

JobOperator Step1 Step2 Step3

Item

Reader

Item

Processor

Item

Writer batchlet

Job

Job Repositoty

Page 92: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 92

アーキテクチャの振り返り

Jobには1つ以上のStepが含まれる

JobやStepはXMLで表現する

Stepの実装方法は2つある

– chunk : 読む/処理/書くを繰り返す処理向き

– batchlet : コマンド向き

chunk/batchletはjavaで実装する

JobOperatorからジョブを起動する

JobRepositoryにジョブ情報は永続化される

Page 93: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 93

Spring Batch と jBatch

Page 94: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 94

Spring Batch と jBatch

jBatch Spring Batch

基本的な作り XMLベース

(ジョブXML)

ユーティリティ クラスの充実

XMLベース (ジョブXML)

現状はなし (シンプルに標準化)

ファイル操作サポート JPA連携サポート

複数サーバ 分散処理

なし あり

JSR準拠 標準仕様

(ベンダフリー) 現状は未準拠

Page 95: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 95

Spring Batch が jBatch仕様準拠の方向へ

次バージョンの Spring Batch 3.0 で対応予定

– issue としては既に登録済み。

– https://jira.springsource.org/issues/?jql=labels%20%3D%20JSR-352

JSR-330(DI標準仕様)でも Spring とJava EE では連携があった

Spring と Java EE が類似する傾向は今後も続くと考える

Page 96: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 96

jBatch 動作環境

Page 97: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 97

対応しているJDK

JDK6 以上 (既にEndOfServiceLifeなので、ぜひJDK7を)

Page 98: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 98

Java SE 環境と EE環境の違い

Java SE Java EE

トランザクション ローカル

トランザクション

スレッド プール

JTA トランザクション

ランタイム実装 に依存

Concurrency Utilities for Java EE (コンテナ管理スレッド)

必要な 設定ファイル

/META-INF/ batch-jobs/job.xml

・/META-INF/ batch-jobs/job.xml ・/META-INF/batch.xml

Page 99: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 99

もっと jBatch を知る

Page 100: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 100

java.net から情報収集

Java EE 7 チュートリアルを読む

– http://docs.oracle.com/javaee/7/tutorial/doc/home.htm

仕様書を読む

– http://jcp.org/aboutJava/communityprocess/final/jsr352/index.html

GlassFish4 を動かしてみる

– GlassFish4にはRI(参照実装)が同梱済み

– Java SE で動かす場合は java.net からダウンロード

– https://java.net/projects/jbatch/downloads/download/jsr352-SE-RI-1.0.zip

Page 101: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 101

Java EE 7書籍も出始めています(洋書)

Java EE Essentials Arun Gupta(著)

Beginning Java EE 7 (日本語訳もあるEE6金魚本の改訂版)

Page 102: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 102

お時間があれば、デモの簡単なご紹介。

https://github.com/n-agetsu/JBatchDemo

Page 103: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 103

GlassFish4 を今すぐダウンロード!

ご清聴ありがとうございました。

OracleとJavaは、Oracle Corporation 及びその子会社、関連会社の米国及びその他の国における登録商標です。文中の社名、商品名等は各社の商標または登録商標である場合があります。

Page 104: 1 Copyright © 2012, Oracle and/or its affiliates. All …...Title Make the Future Java FY13 PPT Template Author Oracle Brand & Creative Created Date 9/12/2013 4:50:23 PM

Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 104