Posts Spring Batch 1
Post
Cancel

Spring Batch 1

Spring Batch 1


๐Ÿ’ฟ DB Schema

Job ๊ด€๋ จ ํ…Œ์ด๋ธ”

  • BATCH_JOB_INSTANCE
    • Job์ด ์‹คํ–‰๋  ๋•Œ JobInstance ์ •๋ณด๊ฐ€ ์ €์žฅ๋˜๋ฉฐ job_name๊ณผ Job_key์„ ํ‚ค๋กœ ํ•˜์—ฌ ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ
    • ๋™์ผํ•œ job_name ๊ณผ job_key๋กœ ์ค‘๋ณต ์ €์žฅ๋  ์ˆ˜ ์—†๋‹ค.
  • BATCH_JOB_EXECUTION
    • job์˜ ์‹คํ–‰์ •๋ณด๊ฐ€ ์ €์žฅ๋˜๋ฉฐ Job ์ƒ์„ฑ, ์‹œ์ž‘, ์ข…๋ฃŒ์‹œ๊ฐ„, ์‹คํ–‰์ƒํƒœ, ๋ฉ”์‹œ์ง€ ๋“ฑ์„ ๊ด€๋ฆฌ
  • BATCH_JOB_EXECUTION_PARAMS
    • Job๊ณผ ํ•จ๊ป˜ ์‹คํ–‰๋˜๋Š” JobParameter ์ •๋ณด๋ฅผ ์ €์žฅ
  • BATCH_JOB_EXECUTION_CONTEXT
    • Job์˜ ์‹คํ–‰๋™์•ˆ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ƒํƒœ์ •๋ณด, ๊ณต์œ  ๋ฐ์ดํ„ฐ๋ฅผ ์ง๋ ฌํ™”(Json ํ˜•์‹) ํ•ด์„œ ์ €์žฅ
    • Step ๊ฐ„ ์„œ๋กœ ๊ณต์œ  ๊ฐ€๋Šฅํ•จ

Step ๊ด€๋ จ ํ…Œ์ด๋ธ”

  • BATCH_STEP_EXECUTION
    • Step์˜ ์‹คํ–‰์ •๋ณด๊ฐ€ ์ €์žฅ๋˜๋ฉฐ ์ƒ์„ฑ, ์‹œ์ž‘ ์ข…๋ฃŒ์‹œ๊ฐ„, ์‹คํ–‰ ์ƒํƒœ, ๋ฉ”์‹œ์ง€ ๋“ฑ์„ ๊ด€๋ฆฌ
  • BATCH_STEP_EXECTION_CONTEXT
    • Step์˜ ์‹คํ–‰๋™์•ˆ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์ƒํƒœ์ •๋ณด, ๊ณต์œ  ๋ฐ์ดํ„ฐ๋ฅผ ์ง๋ ฌํ™”(Json)ํ•ด์„œ ์ €์žฅ
    • Step ๋ณ„๋กœ ์ €์žฅ๋˜๋ฉฐ Step๊ฐ„ ์„œ๋กœ ๊ณต์œ ํ•  ์ˆ˜ ์—†์Œ

๐Ÿ’ฟ Job

image

๋ฐฐ์น˜ ๊ณ„์ธต ๊ตฌ์กฐ์—์„œ ๊ฐ€์žฅ ์ƒ์œ„์— ์žˆ๋Š” ๊ฐœ๋…์œผ๋กœ์„œ ํ•˜๋‚˜์˜ ๋ฐฐ์น˜ ์ž‘์—… ์ž์ฒด๋ฅผ ์˜๋ฏธํ•จ

  • API ์„œ๋ฒ„์˜ ์ ‘์† ๋กœ๊ทธ ๋ฐ์ดํ„ฐ๋ฅผ ํ†ต๊ณ„ ์„œ๋ฒ„๋กœ ์˜ฎ๊ธฐ๋Š” ๋ฐฐ์น˜ -> Job ๊ทธ ์ž์ฒด
  • Job Configuration์„ ํ†ตํ•ด ์ƒ์„ฑ๋˜๋Š” ๊ฐ์ฒด ๋‹จ์œ„๋กœ์„œ ๋ฐฐ์น˜์ž‘์—…์„ ์–ด๋–ป๊ฒŒ ๊ตฌ์„ฑํ•˜๊ณ  ์‹คํ–‰ํ•  ๊ฒƒ์ธ์ง€ ์ „์ฒด์ ์œผ๋กœ ์„ค์ •ํ•˜๊ณ  ๋ช…์„ธํ•ด ๋†“์€ ๊ฐ์ฒด
  • ๋ฐฐ์น˜ Job์„ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ์ตœ์ƒ์œ„ ์ธํ„ฐํŽ˜์ด์Šค์ด๋ฉฐ ์Šคํ”„๋ง ๋ฐฐ์น˜๊ฐ€ ๊ธฐ๋ณธ ๊ตฌํ˜„์ฒด๋ฅผ ์ œ๊ณต
  • ์—ฌ๋Ÿฌ Step์„ ํฌํ•จํ•˜๊ณ  ์žˆ๋Š” ์ปจํ…Œ์ด๋„ˆ๋กœ์„œ ๋ฐ˜๋“œ์‹œ ํ•œ๊ฐœ ์ด์ƒ์˜ Step์œผ๋กœ ๊ตฌ์„ฑํ•ด์•ผ ํ•จ

๊ธฐ๋ณธ ๊ตฌํ˜„์ฒด

  • Simple Job
    • ์ˆœ์ฐจ์ ์œผ๋กœ Step์„ ์‹คํ–‰์‹œํ‚ค๋Š” Job
    • ๋ชจ๋“  Job์—์„œ ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ‘œ์ค€ ๊ธฐ๋Šฅ์„ ๊ฐ–๊ณ  ์žˆ์Œ
  • Flow Job
    • ํŠน์ •ํ•œ ์กฐ๊ฑด๊ณผ ํ๋ฆ„์— ๋”ฐ๋ผ Step์„ ๊ตฌ์„ฑํ•˜์—ฌ ์‹คํ–‰์‹œํ‚ค๋Š” Job
    • Flow ๊ฐ์ฒด๋ฅผ ์‹คํ–‰์‹œ์ผœ์„œ ์ž‘์—…์„ ์ง„ํ–‰ํ•จ

๐Ÿ’ฟ JobInstance

Job์ด ์‹คํ–‰๋  ๋•Œ ์ƒ์„ฑ๋˜๋Š” Job์˜ ๋…ผ๋ฆฌ์  ์‹คํ–‰ ๋‹จ์œ„ ๊ฐ์ฒด๋กœ์„œ ๊ณ ์œ ํ•˜๊ฒŒ ์‹๋ณ„ ๊ฐ€๋Šฅํ•œ ์ž‘์—… ์‹คํ–‰์„ ๋‚˜ํƒ€๋ƒ„

  • Job์˜ ์„ค์ •๊ณผ ๊ตฌ์„ฑ์€ ๋™์ผํ•˜์ง€๋งŒ Job์ด ์‹คํ–‰๋˜๋Š” ์‹œ์ ์— ์ฒ˜๋ฆฌํ•˜๋Š” ๋‚ด์šฉ์€ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— Job์˜ ์‹คํ–‰์„ ๊ตฌ๋ถ„ํ•ด์•ผ ํ•จ
    • ์˜ˆ๋ฅผ ๋“ค์–ด ํ•˜๋ฃจ์— ํ•œ๋ฒˆ ์”ฉ ๋ฐฐ์น˜ Job์ด ์‹คํ–‰๋œ๋‹ค๋ฉด ๋งค์ผ ์‹คํ–‰๋˜๋Š” ๊ฐ๊ฐ์˜ Job์„ JobInstance๋กœ ํ‘œํ˜„ํ•ฉ๋‹ˆ๋‹ค.
  • JobInstance ์ƒ์„ฑ ๋ฐ ์‹คํ–‰
    • ์ฒ˜์Œ ์‹œ์ž‘ํ•˜๋Š” Job + JobParameter(ํ•ด์‰ฌ)์ผ ๊ฒฝ์šฐ ์ƒˆ๋กœ์šด JobInstance ์ƒ์„ฑ
    • ์ด์ „๊ณผ ๋™์ผํ•œ Job + JobParameter์ผ ๊ฒฝ์šฐ ์ด๋ฏธ ์กด์žฌํ•˜๋Š” JobInstance ๋ฆฌํ„ด
    • Job๊ณผ๋Š” 1:M ๊ด€๊ณ„

BATCH_JOB_INSTANCE ํ…Œ์ด๋ธ”๊ณผ ๋งคํ•‘

  • JOB_NAME(Job)rhk JOB_KEY(JobParameter ํ•ด์‹œ๊ฐ’)๊ฐ€ ๋™์ผํ•œ ๋ฐ์ดํ„ฐ๋Š” ์ค‘๋ณตํ•ด์„œ ์ €์žฅํ•  ์ˆ˜ ์—†์Œ

๐Ÿ’ฟ JobParameter

Job์„ ์‹คํ–‰ํ•  ๋•Œ ํ•จ๊ป˜ ํฌํ•จ๋˜์–ด ์‚ฌ์šฉ๋˜๋Š” ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๊ฐ€์ง„ ๋„๋ฉ”์ธ ๊ฐ์ฒด

  • ํ•˜๋‚˜์˜ Job์— ์กด์žฌํ•  ์ˆ˜ ์žˆ๋Š” ์—ฌ๋Ÿฌ๊ฐœ์˜ JobInstance๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ธฐ ์œ„ํ•œ ์šฉ๋„
  • JobParameters์™€ Job Instance๋Š” 1:1 ๊ด€๊ณ„

__

๐Ÿ’ฟ JobExecution

JobInstance์— ๋Œ€ํ•œ ํ•œ๋ฒˆ์˜ ์‹œ๋„๋ฅผ ์˜๋ฏธํ•˜๋Š” ๊ฐ์ฒด๋กœ์„œ Job ์‹คํ–‰ ์ค‘์— ๋ฐœ์ƒํ•œ ์ •๋ณด๋“ค์„ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” ๊ฐ์ฒด

  • ์‹œ์ž‘์‹œ๊ฐ„, ์ข…๋ฃŒ์‹œ๊ฐ„, ์ƒํƒœ(์‹œ์ž‘๋จ, ์™„๋ฃŒ, ์‹คํŒจ)์ข…๋ฃŒ ์ƒํƒœ์˜ ์†์„ฑ์„ ๊ฐ€์ง
  • JobExecution์€ FAILED ๋˜๋Š” COMPLETED ๋“ฑ์˜ Job์˜ ์‹คํ–‰ ๊ฒฐ๊ณผ ์ƒํƒœ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ
  • JobExecution์˜ ์‹คํ–‰ ์ƒํƒœ ๊ฒฐ๊ณผ๊ฐ€ COMPLETED๋ฉด JobInstance ์‹คํ–‰์ด ์™„๋ฃŒ๋œ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผํ•ด์„œ ์žฌ ์‹คํ–‰์ด ๋ถˆ๊ฐ€ํ•จ
  • JobExecution์˜ ์‹คํ–‰ ์ƒํƒœ ๊ฒฐ๊ณผ๊ฐ€ FAILED๋ฉด JobInstance ์‹คํ–‰์ด ์™„๋ฃŒ๋˜์ง€ ์•Š์€ ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผํ•ด์„œ ์žฌ์‹คํ–‰์ด ๊ฐ€๋Šฅํ•จ
    • JobParameter๊ฐ€ ๋™์ผํ•œ ๊ฐ’์œผ๋กœ Job์„ ์‹คํ–‰ํ• ์ง€๋ผ๋„ JobInstance๋ฅผ ๊ณ„์† ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์Œ
  • JobExecution์˜ ์‹คํ–‰ ์ƒํƒœ ๊ฒฐ๊ณผ๊ฐ€ COMPLETED๊ฐ€ ๋  ๋•Œ๊นŒ์ง€ ํ•˜๋‚˜์˜ JobInstance ๋‚ด์—์„œ ์—ฌ๋Ÿฌ๋ฒˆ์˜ ์‹œ๋„๊ฐ€ ์ƒ๊ธธ ์ˆ˜ ์žˆ์Œ
  • JobInstance์™€ JobExecution๋Š” 1:M์˜ ๊ด€๊ณ„๋กœ์„œ JobInstance์— ๋Œ€ํ•œ ์„ฑ๊ณต/์‹คํŒจ์˜ ๋‚ด์—ญ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Œ

๐Ÿ’ฟ Step

Batch Job์„ ๊ตฌ์„ฑํ•˜๋Š” ๋…๋ฆฝ์ ์ธ ํ•˜๋‚˜์˜ ๋‹จ๊ณ„๋กœ์„œ ์‹ค์ œ ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ๋ฅผ ์ •์˜ํ•˜๊ณ  ์ปจํŠธ๋กคํ•˜๋Š” ๋ฐ ํ•„์š”ํ•œ ๋ชจ๋“  ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋„๋ฉ”์ธ ๊ฐ์ฒด

  • ๋‹จ์ˆœํ•œ ๋‹จ์ผ ํƒœ์Šคํฌ ๋ฟ ์•„๋‹ˆ๋ผ ์ž…๋ ฅ๊ณผ ์ฒ˜๋ฆฌ ๊ทธ๋ฆฌ๊ณ  ์ถœ๋ ฅ๊ณผ ๊ด€๋ จ๋œ ๋ณต์žกํ•œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ํฌํ•จํ•˜๋Š” ๋ชจ๋“  ์„ค์ •๋“ค์„ ๋‹ด๊ณ  ์žˆ๋‹ค.
  • ๋ฐฐ์น˜์ž‘์—…์„ ์–ด๋–ป๊ฒŒ ๊ตฌ์„ฑํ•˜๊ณ  ์‹คํ–‰ํ•  ๊ฒƒ์ธ์ง€ Job์˜ ์„ธ๋ถ€ ์ž‘์—…์„ Task ๊ธฐ๋ฐ˜์œผ๋กœ ์„ค์ •ํ•˜๊ณ  ๋ช…์„ธํ•ด ๋†“์€ ๊ฐ์ฒด
  • ๋ชจ๋“  Job์€ ํ•˜๋‚˜ ์ด์ƒ์˜ step์œผ๋กœ ๊ตฌ์„ฑ๋จ

๊ธฐ๋ณธ ๊ตฌํ˜„์ฒด

  • TaskletStep
    • ๊ฐ€์žฅ ๊ธฐ๋ณธ์ด ๋˜๋Š” ํด๋ž˜์Šค๋กœ์„œ Tasklet ํƒ€์ž…์˜ ๊ตฌํ˜„์ฒด๋“ค์„ ์ œ์–ดํ•œ๋‹ค.
  • PartitionStep
    • ๋ฉ€ํ‹ฐ ์Šค๋ ˆ๋“œ ๋ฐฉ์‹์œผ๋กœ Step์„ ์—ฌ๋Ÿฌ ๊ฐœ๋กœ ๋ถ„๋ฆฌํ•ด์„œ ์‹คํ–‰ํ•œ๋‹ค.
  • JobStep
    • Step ๋‚ด์—์„œ Job์„ ์‹คํ–‰ํ•˜๋„๋ก ํ•œ๋‹ค.
  • FlowStep
    • Step ๋‚ด์—์„œ Flow๋ฅผ ์‹คํ–‰ํ•˜๋„๋ก ํ•œ๋‹ค.

๐Ÿ’ฟ StepExecution

Step์— ๋Œ€ํ•œ ํ•œ๋ฒˆ์˜ ์‹œ๋„๋ฅผ ์˜๋ฏธํ•˜๋Š” ๊ฐ์ฒด๋กœ์„œ Step ์‹คํ–‰ ์ค‘์— ๋ฐœ์ƒํ•œ ์ •๋ณด๋“ค์„ ์ €์žฅํ•˜๊ณ  ์žˆ๋Š” ๊ฐ์ฒด

  • ์‹œ์ž‘์‹œ๊ฐ„, ์ข…๋ฃŒ์‹œ๊ฐ„, ์ƒํƒœ, commit count, rollback count ๋“ฑ์˜ ์†์„ฑ์„ ๊ฐ€์ง
  • Step์ด ๋งค๋ฒˆ ์‹œ๋„๋  ๋•Œ๋งˆ๋‹ค ์ƒ์„ฑ๋˜๋ฉฐ ๊ฐ Step ๋ณ„๋กœ ์ƒ์„ฑ๋œ๋‹ค.
  • Job์ด ์žฌ์‹œ์ž‘ ํ•˜๋”๋ผ๋„ ์ด๋ฏธ ์„ฑ๊ณต์ ์œผ๋กœ ์™„๋ฃŒ๋œ Step์€ ์žฌ ์‹คํ–‰๋˜์ง€ ์•Š๊ณ  ์‹คํŒจํ•œ Step๋งŒ ์‹คํ–‰๋œ๋‹ค.
  • ์ด์ „ ๋‹จ๊ณ„ Step์ด ์‹คํŒจํ•ด์„œ ํ˜„์žฌ Step์„ ์‹คํ–‰ํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด StepExecution์„ ์ƒ์„ฑํ•˜์ง€ ์•Š๋Š”๋‹ค. Step์ด ์‹ค์ œ๋กœ ์‹œ์ž‘๋์„ ๋•Œ๋งŒ StepExecition์„ ์ƒ์„ฑํ•œ๋‹ค.

Job Execution ๊ณผ์˜ ๊ด€๊ณ„

  • Step์˜ StepExecution์ด ๋ชจ๋‘ ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ ๋˜์–ด์•ผ JobExecution์ด ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ๋œ๋‹ค.
  • Step์˜ StepExecution ์ค‘ ํ•˜๋‚˜๋ผ๋„ ์‹คํŒจํ•˜๋ฉด JobExecution์€ ์‹คํŒจํ•œ๋‹ค.

BATCH_STEP_EXECUTION ํ…Œ์ด๋ธ”๊ณผ ๋งคํ•‘

  • JobExecution๊ณผ StepExecution์€ 1:M ๊ด€๊ณ„
  • ํ•˜๋‚˜์˜ Job์— ์—ฌ๋Ÿฌ ๊ฐœ์˜ Step์œผ๋กœ ๊ตฌ์„ฑํ–ˆ์„ ๊ฒฝ์šฐ ๊ฐ StepExecution์€ ํ•˜๋‚˜์˜ jobExecution์„ ๋ถ€๋ชจ๋กœ ๊ฐ€์ง„๋‹ค.

๐Ÿ’ฟ StepContribution

Chunk ํ”„๋กœ์„ธ์Šค์˜ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์„ ๋ฒ„ํผ๋ง ํ•œ ํ›„ StepExecution ์ƒํƒœ๋ฅผ ์—…๋ฐ์ดํŠธํ•˜๋Š” ๋„๋ฉ”์ธ ๊ฐ์ฒด

  • ์ฒญํฌ ์ปค๋ฐ‹ ์ง์ „์— StepExecution์˜ apply ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ์ƒํƒœ๋ฅผ ์—…๋ฐ์ดํŠธ ํ•จ
  • ExitStatus์˜ ๊ธฐ๋ณธ ์ข…๋ฃŒ์ฝ”๋“œ ์™ธ ์‚ฌ์šฉ์ž ์ •์˜ ์ข…๋ฃŒ์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ•ด์„œ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Œ

๐Ÿ’ฟ StepContribution

ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ์œ ์ง€ ๋ฐ ๊ด€๋ฆฌํ•˜๋Š” ํ‚ค/๊ฐ’์œผ๋กœ ๋œ ์ปฌ๋ ‰์…˜์œผ๋กœ StepExecution ๋˜๋Š” JobExecution ๊ฐ์ฒด์˜ ์ƒํƒœ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ณต์œ  ๊ฐ์ฒด

  • DB์— ์ง๋ ฌํ™” ํ•œ ๊ฐ’์œผ๋กœ ์ €์žฅ๋จ - (โ€œkeyโ€ : โ€œvalueโ€)
  • ๊ณต์œ  ๋ฒ”์œ„
    • Step ๋ฒ”์œ„ - ๊ฐ Step์˜ StepExecution์— ์ €์žฅ๋˜๋ฉฐ Step๊ฐ„ ์„œ๋กœ ๊ณต์œ  ์•ˆ๋จ
    • Job ๋ฒ”์œ„ - ๊ฐ Job์˜ JobExecution์— ์ €์žฅ๋˜๋ฉฐ Job๊ฐ„ ์„œ๋กœ ๊ณต์œ  ์•ˆ๋˜๋ฉฐ ํ•ด๋‹น Job์˜ Step ๊ฐ„ ์„œ๋กœ ๊ณต์œ ๋จ
  • Job ์žฌ ์‹œ์ž‘์‹œ ์ด๋ฏธ ์ฒ˜๋ฆฌํ•œ Row ๋ฐ์ดํ„ฐ๋Š” ๊ฑด๋„ˆ๋›ฐ๊ณ  ์ดํ›„๋กœ ์ˆ˜ํ–‰ํ•˜๋„๋ก ํ•  ๋•Œ ์ƒํƒœ ์ •๋ณด๋ฅผ ํ™œ์šฉํ•œ๋‹ค.

๐Ÿ’ฟ JobRepository

๋ฐฐ์น˜ ์ž‘์—… ์ค‘์˜ ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๋Š” ์ €์žฅ์†Œ ์—ญํ• 

  • Job์ด ์–ธ์ œ ์ˆ˜ํ–‰๋˜์—ˆ๊ณ  ์–ธ์ œ ๋๋‚ฌ์œผ๋ฉฐ, ๋ช‡๋ฒˆ ์‹คํ–‰๋˜์—ˆ๊ณ  ์‹คํ–‰์— ๋Œ€ํ•œ ๊ฒฐ๊ณผ ๋“ฑ์˜ ๋ฐฐ์น˜ ์ž‘์—…์˜ ์ˆ˜ํ–‰๊ณผ ๊ด€๋ จ๋œ ๋ชจ๋“  meta data๋ฅผ ์ €์žฅ
    • JobLauncher, Job, Step ๊ตฌํ˜„์ฒด ๋‚ด๋ถ€์—์„œ CRUD ๊ธฐ๋Šฅ์„ ์ฒ˜๋ฆฌํ•จ(DB์™€ ์—ฐ๊ฒฐ๋œ ๋ถ€๋ถ„์ด๋ผ๋Š” ๋œป)

JobRepository ์„ค์ •

  • @EnableBatchProcessing ์–ด๋…ธํ…Œ์ด์…˜๋งŒ ์„ ์–ธํ•˜๋ฉด JobRepository๊ฐ€ ์ž๋™์œผ๋กœ ๋นˆ์œผ๋กœ ์ƒ์„ฑ๋จ
  • BatchConfigurer ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•˜๊ฑฐ๋‚˜ BasicBatchConfigurer๋ฅผ ์ƒ์†ํ•ด์„œ JobRepository ์„ค์ •์„ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• ํ•  ์ˆ˜ ์žˆ๋‹ค.
    • JDBC ๋ฐฉ์‹์œผ๋กœ ์„ค์ • - JobRepositoryFactoryBean
      • ๋‚ด๋ถ€์ ์œผ๋กœ AOP ๊ธฐ์ˆ ์„ ํ†ตํ•ด ํŠธ๋žœ์žญ์…˜ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์ฃผ๊ณ  ์žˆ์Œ
      • ํŠธ๋žœ์žญ์…˜ isolation์˜ ๊ธฐ๋ณธ๊ฐ’์€ SERIALIZABLE๋กœ ์ตœ๊ณ  ์ˆ˜์ค€, ๋‹ค๋ฅธ ๋ ˆ๋ฒจ(READ_COMMITED, REPEATABLE_READ)๋กœ ์ง€์ • ๊ฐ€๋Šฅ
      • ๋ฉ”ํƒ€ํ…Œ์ด๋ธ”์˜ Table Prefix๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Œ, ๊ธฐ๋ณธ ๊ฐ’์€ โ€œBATCH_โ€œ์ž„
    • In Memory ๋ฐฉ์‹์œผ๋กœ ์„ค์ • - MapJobRepositoryFactoryBean
      • ์„ฑ๋Šฅ ๋“ฑ์˜ ์ด์œ ๋กœ ๋„๋ฉ”์ธ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ๊ตณ์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅํ•˜๊ณ  ์‹ถ์ง€ ์•Š์„ ๊ฒฝ์šฐ
      • ๋ณดํ†ต Test๋‚˜ ํ”„๋กœํ† ํƒ€์ž…์˜ ๋น ๋ฅธ ๊ฐœ๋ฐœ์ด ํ•„์š”ํ•  ๋•Œ ์‚ฌ์šฉ

๐Ÿ’ฟ JobLauncher

๋ฐฐ์น˜ Job์„ ์‹คํ–‰์‹œํ‚ค๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

  • Job๊ณผ Job Parameters๋ฅผ ์ธ์ž๋กœ ๋ฐ›์œผ๋ฉฐ ์š”์ฒญ๋œ ๋ฐฐ์น˜ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•œ ํ›„ ์ตœ์ข… Client์—๊ฒŒ JobExecution์„ ๋ฐ˜ํ™˜
  • Spring Boot Batch๊ฐ€ ๊ตฌ๋™์ด ๋˜๋ฉด JobLauncher ๋นˆ์ด ์ž๋™ ์ƒ์„ฑ ๋œ๋‹ค.
  • Job ์‹คํ–‰
    • JobLauncher.run(Job, JobParameter)
    • Spring Boot Batch๋Š” JobLauncherApplicationRunner๊ฐ€ ์ž๋™์ ์œผ๋กœ JobLauncher๋ฅผ ์‹คํ–‰์‹œํ‚จ๋‹ค.
    • ๋™๊ธฐ์  ์‹คํ–‰
      • taskExecutor๋ฅผ SyncExecutor๋กœ ์„ค์ •ํ•  ๊ฒฝ์šฐ(๊ธฐ๋ณธ)
      • JobExecution์„ ํš๋“ํ•˜๊ณ  ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ๋ฅผ ์ตœ์ข… ์™„๋ฃŒํ•œ ํ›„ Client์—๊ฒŒ JobExecution์„ ๋ฐ˜ํ™˜
      • ์Šค์ผ€์ค„๋Ÿฌ์— ์˜ํ•œ ๋ฐฐ์น˜์ฒ˜๋ฆฌ์— ์ ํ•ฉ ํ•จ - ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ ์‹œ๊ฐ„์ด ๊ธธ์–ด๋„ ์ƒ๊ด€์—†๋Š” ๊ฒฝ์šฐ
    • ๋น„๋™๊ธฐ์  ์‹คํ–‰
      • taskExecutor๊ฐ€ SimpleAsyncTaskExecutor๋กœ ์„ค์ •ํ•  ๊ฒฝ์šฐ
      • JobExecution์„ ํš๋“ํ•œ ํ›„ Client์—๊ฒŒ ๋ฐ”๋กœ jobExecution์„ ๋ฐ˜ํ™˜ํ•˜๊ณ  ๋ฐฐ์น˜์ฒ˜๋ฆฌ๋ฅผ ์™„๋ฃŒํ•œ๋‹ค.
      • HTTP ์š”์ฒญ์— ์˜ํ•œ ๋ฐฐ์น˜์ฒ˜๋ฆฌ์— ์ ํ•ฉํ•จ - ๋ฐฐ์น˜์ฒ˜๋ฆฌ ์‹œ๊ฐ„์ด ๊ธธ ๊ฒฝ์šฐ ์‘๋‹ต์ด ๋Šฆ์–ด์ง€์ง€ ์•Š๋„๋ก ํ•จ
This post is licensed under CC BY 4.0 by the author.

Spring AOP

Spring Batch 2