ããã¯ããªã«ãããããŠæžãããã®ïŒ
Spring Frameworkã§ã®ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çãšããã°ã宣èšçãã©ã³ã¶ã¯ã·ã§ã³ã䜿ãããšãå€ãã§ãããã
Data Access / Transaction Management / Declarative Transaction Management
äžæ¹ã§ã宣èšçãã©ã³ã¶ã¯ã·ã§ã³ã§ã¯ããã©ã«ãã§ã¯RuntimeException
ïŒãšError
ïŒãããŒã«ããã¯å¯Ÿè±¡ãšãªããException
âŠãããã
æ€æ»äŸå€ã¯ããŒã«ããã¯ãããªãããšãç¥ãããŠããŸãã
In its default configuration, the Spring Frameworkâs transaction infrastructure code marks a transaction for rollback only in the case of runtime, unchecked exceptions. That is, when the thrown exception is an instance or subclass of RuntimeException. (Error instances also, by default, result in a rollback). Checked exceptions that are thrown from a transactional method do not result in rollback in the default configuration.
Data Access / Transaction Management / Rolling Back a Declarative Transaction
Spring Batchã§ã¯ããã©ã³ã¶ã¯ã·ã§ã³ç®¡çãSpring BatchåŽãè¡ããšããããšãªã®ã§ãããã¹ããŒãããäŸå€ãRuntimeException
ãªã®ã
Exception
ãªã®ãã§æåãå€ããã®ãã©ãããæ°ã«ãªã£ãã®ã§ã調ã¹ãŠã¿ãããšã«ããŸããã
Spring Batchã®ãã©ã³ã¶ã¯ã·ã§ã³ç®¡ç
ãŸãã¯ãSpring Batchã®ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çã«é¢ããããã¥ã¡ã³ããèŠãŠã¿ãŸãããã
ãã©ã³ã¶ã¯ã·ã§ã³ã«é¢ããèšè¿°ã¯ããã®ãããã®ããã¥ã¡ã³ãã«æžãããŠããããã§ãã
Batch Processing and Transactions
äž»ã«ã¯ããã£ã³ã¯æåã®åŠçã§èª¬æãæžãããŠããŸãããã©ã³ã¶ã¯ã·ã§ã³ã®åäœãããã£ã³ã¯ãšããããŒã¿ã®ãŸãšãŸãã«ãªããšãã
話ã§ããã
Chunk oriented processing refers to reading the data one at a time and creating 'chunks' that are written out within a transaction boundary. Once the number of items read equals the commit interval, the entire chunk is written out by the ItemWriter, and then the transaction is committed.
Configuring a Step / Chunk-oriented Processing
ããšãã°ããã£ã³ã¯ã®ãµã€ãºã100ãªããã¹ãããçãèããªããã°ããŒã¿100ä»¶ããšã«ã²ãšã€ã®ãã©ã³ã¶ã¯ã·ã§ã³ãšããŠæ±ãããããšã«
ãªããŸãã
ãã£ã³ã¯ãµã€ãºã¯ãã³ãããééãšããŠã説æãããŠããŸãã
As mentioned previously, a step reads in and writes out items, periodically committing using the supplied PlatformTransactionManager. With a commit-interval of 1, it commits after writing each individual item. This is less than ideal in many situations, since beginning and committing a transaction is expensive. Ideally, it is preferable to process as many items as possible in each transaction, which is completely dependent upon the type of data being processed and the resources with which the step is interacting.
Configuring a Step / Chunk-oriented Processing / The Commit Interval
ããŒã«ããã¯å¶åŸ¡ã®èª¬ã§ã¯ãItemWriter
ã«ãã£ãŠäŸå€ãã¹ããŒããããšããŒã«ããã¯ãããããšãæžãããŠããŸãã
By default, regardless of retry or skip, any exceptions thrown from the ItemWriter cause the transaction controlled by the Step to rollback.
Configuring a Step / Chunk-oriented Processing / Controlling Rollback
ããèªããšãItemReader
ãšItemProcessor
ã¯ã©ããªãã§ããããïŒ
ItemReader
ã«é¢ããŠã¯ãJMSãã¥ãŒãæ±ãå Žåãªã©ã®ãã©ã³ã¶ã¯ã·ã§ãã«ãªãªãœãŒã¹ãæ±ãéã«ããã¥ãŒããååŸããã¡ãã»ãŒãžã
æ»ããªãããã«ãããã¡ãªã³ã°ããªãããèšå®ããæ¹æ³ãæžãããŠããŸãã
Configuring a Step / Chunk-oriented Processing / Controlling Rollback / Transactional Readers
ããèŠããšãItemReader
ããã©ã³ã¶ã¯ã·ã§ã³ã®ç¯å²ã«å«ãŸããŠãããã§ãããããã§ãã£ãŠæ¬²ããã§ããã
ã¡ãªã¿ã«ãListenerãšãã©ã³ã¶ã¯ã·ã§ã³ã®é¢ä¿ã«ã€ããŠãããã¥ã¡ã³ãã«æžãããŠããŸãã
Configuring a Step / Chunk-oriented Processing / Intercepting Step Execution
ãã£ã³ã¯ã«å¯ŸããŠTasklet
ã®å Žåã¯ãã·ã³ãã«ã«ãã©ã³ã¶ã¯ã·ã§ã³ã«ã©ãããããããšãæžãããŠããŸãã
Each call to a Tasklet is wrapped in a transaction.
Configuring a Step / TaskletStep
äžæ¹ã§ããã¡ãã®ããã¥ã¡ã³ãâŠä»é²ã«ã¯ãããã®æ§æã®ããªãšãŒã·ã§ã³ãšãã©ã³ã¶ã¯ã·ã§ã³ã®é¢ä¿ããŸãšããããŠããŸããã
Batch Processing and Transactions
ã·ã³ãã«ãªåŠçãã¿ãŒã³ã§ã¯ããããŸã§èŠãŠããæ å ±ïŒç¹ã«ãã£ã³ã¯ïŒãç°¡æœã«ãŸãšããããŠããã ãã§ããã
Appendix A: Batch Processing and Transactions / Simple Batching with No Retry
ããã¥ã¡ã³ãããåŸãããæ å ±ã¯ããããããªã®ã§ãããšã¯å®éã«åãããŠç¢ºèªããŠã¿ããšããŸãããã
ãé¡
ä»åã®ãé¡ã¯ããã¡ãã
- ãã£ã³ã¯ãš
Tasklet
ãããããã§Job
ãæ§æãã Job
ã®å 容ã¯ãList
ã«å®çŸ©ããããŒã¿10ä»¶ãJPAã§ããŒã¿ããŒã¹ã«æžã蟌ãåŠçãšãã- ãã£ã³ã¯
- ããŒã¿ã10ä»¶çšæããŠããã£ã³ã¯ãµã€ãºã¯3ä»¶ãšãã
- äžå®ã®ä»¶æ°ãåŠçããåŸã§ã
RuntimeException
ããã³Exception
ãItemReader
ãItemProcessor
ãItemWriter
ããããããäŸå€ãã¹ããŒããŠåäœã確èªãã
Tasklet
- ããŒã¿ã10ä»¶çšæããŠäžå®ã®ä»¶æ°ãåŠçããåŸã§ã
RuntimeException
ããã³Exception
ãTasklet
ããäŸå€ãã¹ããŒããŠåäœã確èªãã
- ããŒã¿ã10ä»¶çšæããŠäžå®ã®ä»¶æ°ãåŠçããåŸã§ã
ãã®ããªãšãŒã·ã§ã³ã確èªããŠã¿ãŸãã
ç°å¢
ä»åã®ç°å¢ã¯ããã¡ãã
$ java --version openjdk 17.0.3 2022-04-19 OpenJDK Runtime Environment (build 17.0.3+7-Ubuntu-0ubuntu0.20.04.1) OpenJDK 64-Bit Server VM (build 17.0.3+7-Ubuntu-0ubuntu0.20.04.1, mixed mode, sharing) $ mvn --version Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0) Maven home: $HOME/.sdkman/candidates/maven/current Java version: 17.0.3, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64 Default locale: ja_JP, platform encoding: UTF-8 OS name: "linux", version: "5.4.0-110-generic", arch: "amd64", family: "unix"
ããŒã¿ããŒã¹ã«ã¯ãMySQLã䜿çšããŸããMySQLã¯ã172.17.0.2ã§åäœããŠãããã®ãšããŸãã
$ mysql --version mysql Ver 8.0.29 for Linux on x86_64 (MySQL Community Server - GPL)
ãããžã§ã¯ããäœæãã
ãŸãã¯ãSpring Bootãããžã§ã¯ããäœæããŸããäŸåé¢ä¿ã«ã¯ãbatch
ãdata-jpa
ãmysql
ãå ããŸããã
$ curl -s https://start.spring.io/starter.tgz \ -d bootVersion=2.7.0 \ -d javaVersion=17 \ -d name=batch-transaction \ -d groupId=org.littlewings \ -d artifactId=batch-transaction \ -d version=0.0.1-SNAPSHOT \ -d packageName=org.littlewings.spring.batch \ -d dependencies=batch,data-jpa,mysql \ -d baseDir=batch-transaction | tar zxvf -
ãããžã§ã¯ãå ã«ç§»åã
$ cd batch-transaction
çæããããœãŒã¹ã³ãŒãã¯ãåé€ããŠãããŸãã
$ rm src/main/java/org/littlewings/spring/batch/BatchTransactionApplication.java src/test/java/org/littlewings/spring/batch/BatchTransactionApplicationTests.java
Mavenã®äŸåé¢ä¿ããã©ã°ã€ã³ã®èšå®ã¯ããã¡ãã
<properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-batch</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.batch</groupId> <artifactId>spring-batch-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>
ä»åã®ããŒãã«å®çŸ©ã¯ããã¡ãã«ããŸãããæžç±ããé¡ã«ããŸãã
src/main/resources/schema.sql
drop table if exists book; create table book ( isbn varchar(14), title varchar(100), price int, primary key(isbn) );
察å¿ããJPAã®Entityã
src/main/java/org/littlewings/spring/batch/Book.java
package org.littlewings.spring.batch; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = "book") public class Book { @Id @Column(name = "isbn") String isbn; @Column(name = "title") String title; @Column(name = "price") Integer price; public static Book create(String isbn, String title, Integer price) { Book book = new Book(); book.setIsbn(isbn); book.setTitle(title); book.setPrice(price); return book; } // getterïŒsetterã¯çç¥ }
main
ã¯ã©ã¹ã
src/main/java/org/littlewings/spring/batch/App.java
package org.littlewings.spring.batch; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @EnableBatchProcessing public class App { public static void main(String... args) { SpringApplication.run(App.class, args); } }
èšå®ã
src/main/resources/application.properties
spring.datasource.url=jdbc:mysql://172.17.0.2:3306/practice?characterEncoding=utf-8 spring.datasource.username=kazuhira spring.datasource.password=password spring.sql.init.mode=always spring.batch.jdbc.initialize-schema=always logging.level.org.springframework.batch.core.step=debug logging.level.org.springframework.transaction=debug
ã¢ããªã±ãŒã·ã§ã³ã䜿çšããããŒãã«ããSpring Batchã䜿çšãã䜿çšããããŒãã«ã¯èµ·åæã«äœæããããã«ããŸããã
ããšã¯ããã£ã³ã¯ãšTasklet
ã®Job
ãäœæãã€ã€åäœç¢ºèªããŠãããŸãããã
ãã£ã³ã¯
ãã£ã³ã¯ãæ§æãããItemReader
ãItemProcessor
ãItemWriter
ã以äžã®ããã«äœæã
ItemReader
ã
src/main/java/org/littlewings/spring/batch/BookItemReader.java
package org.littlewings.spring.batch; import java.util.Iterator; import java.util.List; import org.springframework.batch.item.NonTransientResourceException; import org.springframework.batch.item.ParseException; import org.springframework.batch.item.UnexpectedInputException; import org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader; import org.springframework.batch.item.support.AbstractItemStreamItemReader; public class BookItemReader extends AbstractItemStreamItemReader<Book> { Iterator<Book> bookIterator; int currentCount = 0; public BookItemReader() { List<Book> books = List.of( Book.create("978-4798142470", "Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº", 4400), Book.create("978-4774182179", "[æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ãã£", 4180), Book.create("978-1492076988", "Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications", 6265), Book.create("978-1484237236", "The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud", 7361), Book.create("978-4798161488", "MySQL培åºå ¥é 第4ç MySQL 8.0察å¿", 4180), Book.create("978-4797393118", "åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº)", 6038), Book.create("978-4873116389", "å®è·µãã€ããã©ãŒãã³ã¹MySQL 第3ç", 5280), Book.create("978-4295000198", "ããããåŠã¹ãMySQLéçšã»ç®¡çå ¥éã5.7察å¿ã", 2860), Book.create("978-4798147406", "詳解MySQL 5.7 æ¢ãŸãã¬é²åã«ä¹ãé ããªãããã®ãã¯ãã«ã«ã¬ã€ã (NEXT ONE)", 3960), Book.create("978-4774170206", "MariaDB&MySQLå šæ©èœãã€ãã«", 3860) ); bookIterator = books.iterator(); } @Override public Book read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } if (bookIterator.hasNext()) { return bookIterator.next(); } else { return null; } } }
10ä»¶ã®æžç±ããŒã¿ãæ±ãããšã«ããŸãã
ItemProcessor
ã
src/main/java/org/littlewings/spring/batch/BookItemProcessor.java
package org.littlewings.spring.batch; import org.springframework.batch.item.ItemProcessor; public class BookItemProcessor implements ItemProcessor<Book, Book> { int currentCount = 0; @Override public Book process(Book item) throws Exception { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } return item; } }
ItemWriter
ã
src/main/java/org/littlewings/spring/batch/BookItemWriter.java
package org.littlewings.spring.batch; import java.util.List; import javax.persistence.EntityManager; import org.springframework.batch.item.support.AbstractItemStreamItemWriter; import org.springframework.beans.factory.annotation.Autowired; public class BookItemWriter extends AbstractItemStreamItemWriter<Book> { @Autowired EntityManager entityManager; int currentCount = 0; @Override public void write(List<? extends Book> items) throws Exception { for (Book book : items) { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } entityManager.persist(book); entityManager.flush(); } } }
ItemWriter
ã¯ãããŒã¿1ä»¶ãã€ãã©ãã·ã¥ããããã«ããŠããŸããSQLãããã«å®è¡ãããããã§ããã
ãããã«ãå
±éã®ãã¿ãŒã³ããããŸããã7ä»¶ç®ã®ããŒã¿ãæ±ããšããã§ã³ã¡ã³ãã¢ãŠããè§£é€ãããšäŸå€ãã¹ããŒããããã«ãªã£ãŠããŸãã
RuntimeException
ããã³Exception
ã§ãã
if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); }
ItemReader
ãItemProcessor
ãItemWriter
ããããã§ãã®ã³ã¡ã³ãã¢ãŠãã®è§£é€ãå€åããã€ã€ãã©ã®ãããªåããããããèŠãŠãããŸãã
Job
ã®å®çŸ©ã¯ãã¡ãã
src/main/java/org/littlewings/spring/batch/ChunkJobConfig.java
package org.littlewings.spring.batch; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepScope; import org.springframework.batch.core.launch.support.RunIdIncrementer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class ChunkJobConfig { @Bean public Job chunkJob(JobBuilderFactory jobBuilderFactory) { return jobBuilderFactory .get("chunkJob") .incrementer(new RunIdIncrementer()) .start(chunkStep(null)) .build(); } @Bean public Step chunkStep(StepBuilderFactory stepBuilderFactory) { return stepBuilderFactory .get("chunkStep") .<Book, Book>chunk(3) .reader(bookItemReader()) .processor(bookItemProcessor()) .writer(bookItemWriter()) .build(); } @Bean @StepScope public BookItemReader bookItemReader() { return new BookItemReader(); } @Bean @StepScope public BookItemProcessor bookItemProcessor() { return new BookItemProcessor(); } @Bean @StepScope public BookItemWriter bookItemWriter() { return new BookItemWriter(); } }
ãã£ã³ã¯ãµã€ãºã¯3ãšããŠããŸããã€ãŸããã³ã¡ã³ãã¢ãŠããè§£é€ãããšã3ã€ç®ã®ãã£ã³ã¯ã®åŠçäžã«äŸå€ãã¹ããŒãããããšã«
ãªããŸããã
ã§ã¯ã確èªããŠãããŸãããã
確èªã¯ããœãŒã¹ã³ãŒãã倿Žãã€ã€ããã±ãŒãžã³ã°ããŠ
$ mvn package
Job
ãæå®ããŠå®è¡ããããšã«ããŸãã
$ java -Dspring.batch.job.names=chunkJob -jar target/batch-transaction-0.0.1-SNAPSHOT.jar
æ£åžžã«çµäºããå Žå
ãŸãã¯ãæ£åžžã«çµäºããå Žåããã
å®è¡æã®ãã°ã¯ãã¡ãã
2022-05-27 01:22:22.882 INFO 20890 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:22:23.417 INFO 20890 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] launched with the following parameters: [{run.id=1}] 2022-05-27 01:22:23.628 INFO 20890 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [chunkStep] 2022-05-27 01:22:23.629 DEBUG 20890 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=1 2022-05-27 01:22:23.944 DEBUG 20890 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:22:23.945 DEBUG 20890 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:22:23.953 DEBUG 20890 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=1, version=1, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=3, filterCount=0, writeCount=3 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription= 2022-05-27 01:22:24.072 DEBUG 20890 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:22:24.073 DEBUG 20890 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:22:24.076 DEBUG 20890 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=1, version=2, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=6, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=0, exitDescription= 2022-05-27 01:22:24.343 DEBUG 20890 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:22:24.344 DEBUG 20890 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:22:24.345 DEBUG 20890 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=1, version=3, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=9, filterCount=0, writeCount=9 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=3, rollbackCount=0, exitDescription= 2022-05-27 01:22:24.510 DEBUG 20890 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: true 2022-05-27 01:22:24.510 DEBUG 20890 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=1, written=1, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:22:24.512 DEBUG 20890 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=1, version=4, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=10, filterCount=0, writeCount=10 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=4, rollbackCount=0, exitDescription= 2022-05-27 01:22:24.576 DEBUG 20890 --- [ main] o.s.batch.core.step.AbstractStep : Step execution success: id=1 2022-05-27 01:22:24.580 INFO 20890 --- [ main] o.s.batch.core.step.AbstractStep : Step: [chunkStep] executed in 950ms 2022-05-27 01:22:24.698 DEBUG 20890 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=1, version=6, name=chunkStep, status=COMPLETED, exitStatus=COMPLETED, readCount=10, filterCount=0, writeCount=10 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=4, rollbackCount=0 2022-05-27 01:22:24.757 INFO 20890 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] completed with the following parameters: [{run.id=1}] and the following status: [COMPLETED] in 1s268ms
ããŒã¿ã¯ãããªããŸããã
mysql> select * from book; +----------------+---------------------------------------------------------------------------------------------------------+-------+ | isbn | title | price | +----------------+---------------------------------------------------------------------------------------------------------+-------+ | 978-1484237236 | The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud | 7361 | | 978-1492076988 | Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications | 6265 | | 978-4295000198 | ããããåŠã¹ãMySQLéçšã»ç®¡çå ¥éã5.7察å¿ã | 2860 | | 978-4774170206 | MariaDB&MySQLå šæ©èœãã€ãã« | 3860 | | 978-4774182179 | [æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ã㣠| 4180 | | 978-4797393118 | åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº) | 6038 | | 978-4798142470 | Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº | 4400 | | 978-4798147406 | 詳解MySQL 5.7 æ¢ãŸãã¬é²åã«ä¹ãé ããªãããã®ãã¯ãã«ã«ã¬ã€ã (NEXT ONE) | 3960 | | 978-4798161488 | MySQL培åºå ¥é 第4ç MySQL 8.0å¯Ÿå¿ | 4180 | | 978-4873116389 | å®è·µãã€ããã©ãŒãã³ã¹MySQL 第3ç | 5280 | +----------------+---------------------------------------------------------------------------------------------------------+-------+ 10 rows in set (0.00 sec)
ItemReaderãäŸå€ãã¹ããŒããå Žå
次ã¯ãItemReader
ãäŸå€ãã¹ããŒããå Žåã§ãã
ãŸãã¯ãRuntimeException
ãã¹ããŒããŠã¿ãŸãã
@Override public Book read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { currentCount++; if (currentCount > 7) { throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } if (bookIterator.hasNext()) { return bookIterator.next(); } else { return null; } }
ãã°ã
2022-05-27 01:23:27.851 INFO 21357 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:23:28.190 INFO 21357 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] launched with the following parameters: [{run.id=2}] 2022-05-27 01:23:28.312 INFO 21357 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [chunkStep] 2022-05-27 01:23:28.312 DEBUG 21357 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=2 2022-05-27 01:23:28.531 DEBUG 21357 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:23:28.532 DEBUG 21357 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:23:28.536 DEBUG 21357 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=2, version=1, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=3, filterCount=0, writeCount=3 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription= 2022-05-27 01:23:28.575 DEBUG 21357 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:23:28.575 DEBUG 21357 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:23:28.577 DEBUG 21357 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=2, version=2, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=6, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=0, exitDescription= 2022-05-27 01:23:28.607 DEBUG 21357 --- [ main] o.s.b.c.step.item.SimpleChunkProvider : Oops!! : java.lang.RuntimeException 2022-05-27 01:23:28.607 DEBUG 21357 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=1, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:23:28.607 DEBUG 21357 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:23:28.612 DEBUG 21357 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:38) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:12) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader$$FastClassBySpringCGLIB$$29093ae.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemReader$$EnhancerBySpringCGLIB$$9a856c3.read(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:99) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:180) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:126) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:118) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:71) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:23:28.619 ERROR 21357 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step chunkStep in job chunkJob java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:38) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:12) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader$$FastClassBySpringCGLIB$$29093ae.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemReader$$EnhancerBySpringCGLIB$$9a856c3.read(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:99) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:180) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:126) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:118) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:71) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:23:28.625 INFO 21357 --- [ main] o.s.batch.core.step.AbstractStep : Step: [chunkStep] executed in 313ms 2022-05-27 01:23:28.658 DEBUG 21357 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=2, version=4, name=chunkStep, status=FAILED, exitStatus=FAILED, readCount=7, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=1 2022-05-27 01:23:28.693 INFO 21357 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] completed with the following parameters: [{run.id=2}] and the following status: [FAILED] in 448ms
ããŒã«ããã¯ã衚ããã°ãåºåãããŠããŸããã¡ãªã¿ã«ãDEBUGã¬ãã«ã§ããã
2022-05-27 01:23:28.607 DEBUG 21357 --- [ main] o.s.b.c.step.item.SimpleChunkProvider : Oops!! : java.lang.RuntimeException 2022-05-27 01:23:28.607 DEBUG 21357 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=1, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:23:28.607 DEBUG 21357 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:23:28.612 DEBUG 21357 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!!
ããŒã¿ã¯ããã£ã³ã¯2ã€åã ããå ¥ã£ãŠããŸããã3ã€ç®ã®ãã£ã³ã¯ã¯å ¥ã£ãŠããŸããã
mysql> select * from book; +----------------+---------------------------------------------------------------------------------------------------------+-------+ | isbn | title | price | +----------------+---------------------------------------------------------------------------------------------------------+-------+ | 978-1484237236 | The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud | 7361 | | 978-1492076988 | Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications | 6265 | | 978-4774182179 | [æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ã㣠| 4180 | | 978-4797393118 | åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº) | 6038 | | 978-4798142470 | Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº | 4400 | | 978-4798161488 | MySQL培åºå ¥é 第4ç MySQL 8.0å¯Ÿå¿ | 4180 | +----------------+---------------------------------------------------------------------------------------------------------+-------+ 6 rows in set (0.01 sec)
ä»åºŠã¯ãException
ãã¹ããŒããŠã¿ãŸãã
@Override public Book read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); throw new Exception("Oops!!"); } if (bookIterator.hasNext()) { return bookIterator.next(); } else { return null; } }
ãã°ã
2022-05-27 01:25:29.476 INFO 21604 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:25:29.829 INFO 21604 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] launched with the following parameters: [{run.id=3}] 2022-05-27 01:25:29.931 INFO 21604 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [chunkStep] 2022-05-27 01:25:29.932 DEBUG 21604 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=3 2022-05-27 01:25:30.098 DEBUG 21604 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:25:30.098 DEBUG 21604 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:25:30.101 DEBUG 21604 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=3, version=1, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=3, filterCount=0, writeCount=3 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription= 2022-05-27 01:25:30.145 DEBUG 21604 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:25:30.145 DEBUG 21604 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:25:30.147 DEBUG 21604 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=3, version=2, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=6, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=0, exitDescription= 2022-05-27 01:25:30.194 DEBUG 21604 --- [ main] o.s.b.c.step.item.SimpleChunkProvider : Oops!! : java.lang.Exception 2022-05-27 01:25:30.195 DEBUG 21604 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=1, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:25:30.195 DEBUG 21604 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: org.springframework.batch.repeat.RepeatException: Exception in batch process; nested exception is java.lang.Exception: Oops!! 2022-05-27 01:25:30.201 DEBUG 21604 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.repeat.RepeatException: Exception in batch process; nested exception is java.lang.Exception: Oops!! at org.springframework.batch.repeat.support.RepeatTemplate.rethrow(RepeatTemplate.java:320) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:256) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:118) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:71) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] Caused by: java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:39) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:12) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader$$FastClassBySpringCGLIB$$29093ae.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemReader$$EnhancerBySpringCGLIB$$b4130ec4.read(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:99) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:180) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:126) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] ... 50 common frames omitted 2022-05-27 01:25:30.208 ERROR 21604 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step chunkStep in job chunkJob java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:39) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:12) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader$$FastClassBySpringCGLIB$$29093ae.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemReader$$EnhancerBySpringCGLIB$$b4130ec4.read(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:99) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider.read(SimpleChunkProvider.java:180) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:126) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:118) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:71) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:25:30.215 INFO 21604 --- [ main] o.s.batch.core.step.AbstractStep : Step: [chunkStep] executed in 283ms 2022-05-27 01:25:30.258 DEBUG 21604 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=3, version=4, name=chunkStep, status=FAILED, exitStatus=FAILED, readCount=7, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=1 2022-05-27 01:25:30.315 INFO 21604 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] completed with the following parameters: [{run.id=3}] and the following status: [FAILED] in 412ms
ããŒã«ããã¯ãããããã§ãã
ç»é²ãããããŒã¿æ°ã«ã¯ãå€åããããŸããã
mysql> select * from book; +----------------+---------------------------------------------------------------------------------------------------------+-------+ | isbn | title | price | +----------------+---------------------------------------------------------------------------------------------------------+-------+ | 978-1484237236 | The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud | 7361 | | 978-1492076988 | Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications | 6265 | | 978-4774182179 | [æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ã㣠| 4180 | | 978-4797393118 | åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº) | 6038 | | 978-4798142470 | Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº | 4400 | | 978-4798161488 | MySQL培åºå ¥é 第4ç MySQL 8.0å¯Ÿå¿ | 4180 | +----------------+---------------------------------------------------------------------------------------------------------+-------+ 6 rows in set (0.00 sec)
ãã°ã«é¢ããŠã¯ãããããèŠããšã¹ã¿ãã¯ãã¬ãŒã¹ãå€ãã£ãŠããŸãã
RuntimeException
ã®å Žåã
2022-05-27 01:23:28.607 DEBUG 21357 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:23:28.612 DEBUG 21357 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:38) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:12) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader$$FastClassBySpringCGLIB$$29093ae.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] ãçç¥ã
Exception
ã®å Žåã
2022-05-27 01:25:30.195 DEBUG 21604 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: org.springframework.batch.repeat.RepeatException: Exception in batch process; nested exception is java.lang.Exception: Oops!! 2022-05-27 01:25:30.201 DEBUG 21604 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.repeat.RepeatException: Exception in batch process; nested exception is java.lang.Exception: Oops!! at org.springframework.batch.repeat.support.RepeatTemplate.rethrow(RepeatTemplate.java:320) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:256) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:118) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:71) ~[spring-batch-core-4.3.6.jar!/:4.3.6] ãçç¥ã Caused by: java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:39) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader.read(BookItemReader.java:12) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemReader$$FastClassBySpringCGLIB$$29093ae.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] ãçç¥ã
ããèŠããšãException
ã®æ¹ã¯ãã¹ãããäŸå€ã«ãªã£ãŠããŸãããããŠRuntimeException
ã§ããŒã«ããã¯ããããšã«ãªã£ãŠããŸãã
2022-05-27 01:25:30.195 DEBUG 21604 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: org.springframework.batch.repeat.RepeatException: Exception in batch process; nested exception is java.lang.Exception: Oops!!
ã©ããããã©ããããŠåã¹ããŒããŠããããã§ãããRepeatException
ãã¹ããŒããããšã«ãªã£ãŠããŸãã
2022-05-27 01:25:30.201 DEBUG 21604 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.repeat.RepeatException: Exception in batch process; nested exception is java.lang.Exception: Oops!! at org.springframework.batch.repeat.support.RepeatTemplate.rethrow(RepeatTemplate.java:320) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6]
RuntimeException
ãã¹ããŒããæã®æ¹ããçŽ çŽãªåãã§ããã
çµè«ãšããŠã¯ãRuntimeException
ã§ãException
ã§ãããŒã«ããã¯ããããšãããããŸããã
ItemReader
ã¯ããã£ããå
ã«æ»ããŸãã
@Override public Book read() throws Exception, UnexpectedInputException, ParseException, NonTransientResourceException { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } if (bookIterator.hasNext()) { return bookIterator.next(); } else { return null; } }
ItemProcessorãäŸå€ãã¹ããŒããå Žå
次ã¯ãItemProcessor
ã«ç§»ããŸãããã
RuntimeException
ãã¹ããŒããŠã¿ãŸãã
@Override public Book process(Book item) throws Exception { currentCount++; if (currentCount > 7) { throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } return item; }
å®è¡ãã°ã
2022-05-27 01:29:23.714 INFO 21982 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:29:24.011 INFO 21982 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] launched with the following parameters: [{run.id=4}] 2022-05-27 01:29:24.163 INFO 21982 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [chunkStep] 2022-05-27 01:29:24.163 DEBUG 21982 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=4 2022-05-27 01:29:24.390 DEBUG 21982 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:29:24.390 DEBUG 21982 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:29:24.393 DEBUG 21982 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=4, version=1, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=3, filterCount=0, writeCount=3 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription= 2022-05-27 01:29:24.429 DEBUG 21982 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:29:24.429 DEBUG 21982 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:29:24.431 DEBUG 21982 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=4, version=2, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=6, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=0, exitDescription= 2022-05-27 01:29:24.461 DEBUG 21982 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:29:24.461 DEBUG 21982 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:29:24.465 DEBUG 21982 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:13) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:5) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor$$FastClassBySpringCGLIB$$775ca5c7.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemProcessor$$EnhancerBySpringCGLIB$$acf7a11d.process(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:134) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:319) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:210) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:29:24.471 ERROR 21982 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step chunkStep in job chunkJob java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:13) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:5) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor$$FastClassBySpringCGLIB$$775ca5c7.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemProcessor$$EnhancerBySpringCGLIB$$acf7a11d.process(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:134) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:319) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:210) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:29:24.475 INFO 21982 --- [ main] o.s.batch.core.step.AbstractStep : Step: [chunkStep] executed in 312ms 2022-05-27 01:29:24.502 DEBUG 21982 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=4, version=4, name=chunkStep, status=FAILED, exitStatus=FAILED, readCount=9, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=1 2022-05-27 01:29:24.534 INFO 21982 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] completed with the following parameters: [{run.id=4}] and the following status: [FAILED] in 466ms
ãã¡ããããŒã«ããã¯ããŠããããã§ãã
2022-05-27 01:29:24.461 DEBUG 21982 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:29:24.465 DEBUG 21982 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:13) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:5) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor$$FastClassBySpringCGLIB$$775ca5c7.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20]
ããŒã¿ã2ã€ã®ãã£ã³ã¯åã®ããŒã¿ãŸã§ãå ¥ã£ãŠããŸããã
mysql> select * from book; +----------------+---------------------------------------------------------------------------------------------------------+-------+ | isbn | title | price | +----------------+---------------------------------------------------------------------------------------------------------+-------+ | 978-1484237236 | The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud | 7361 | | 978-1492076988 | Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications | 6265 | | 978-4774182179 | [æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ã㣠| 4180 | | 978-4797393118 | åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº) | 6038 | | 978-4798142470 | Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº | 4400 | | 978-4798161488 | MySQL培åºå ¥é 第4ç MySQL 8.0å¯Ÿå¿ | 4180 | +----------------+---------------------------------------------------------------------------------------------------------+-------+ 6 rows in set (0.00 sec)
Exception
ãã¹ããŒããŠã¿ãŸãã
@Override public Book process(Book item) throws Exception { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); throw new Exception("Oops!!"); } return item; }
ãã°ã
2022-05-27 01:30:47.367 INFO 22148 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:30:47.672 INFO 22148 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] launched with the following parameters: [{run.id=5}] 2022-05-27 01:30:47.815 INFO 22148 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [chunkStep] 2022-05-27 01:30:47.815 DEBUG 22148 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=5 2022-05-27 01:30:48.011 DEBUG 22148 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:30:48.011 DEBUG 22148 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:30:48.014 DEBUG 22148 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=5, version=1, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=3, filterCount=0, writeCount=3 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription= 2022-05-27 01:30:48.049 DEBUG 22148 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:30:48.050 DEBUG 22148 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:30:48.052 DEBUG 22148 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=5, version=2, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=6, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=0, exitDescription= 2022-05-27 01:30:48.083 DEBUG 22148 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:30:48.083 DEBUG 22148 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for Exception: java.lang.Exception: Oops!! 2022-05-27 01:30:48.088 DEBUG 22148 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.Exception: Oops!! at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:487) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] Caused by: java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:14) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:5) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor$$FastClassBySpringCGLIB$$775ca5c7.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemProcessor$$EnhancerBySpringCGLIB$$acf7a11d.process(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:134) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:319) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:210) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] ... 46 common frames omitted 2022-05-27 01:30:48.094 ERROR 22148 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step chunkStep in job chunkJob java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:14) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:5) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor$$FastClassBySpringCGLIB$$775ca5c7.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemProcessor$$EnhancerBySpringCGLIB$$acf7a11d.process(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:134) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:319) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:210) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:30:48.100 INFO 22148 --- [ main] o.s.batch.core.step.AbstractStep : Step: [chunkStep] executed in 284ms 2022-05-27 01:30:48.154 DEBUG 22148 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=5, version=4, name=chunkStep, status=FAILED, exitStatus=FAILED, readCount=9, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=1 2022-05-27 01:30:48.205 INFO 22148 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] completed with the following parameters: [{run.id=5}] and the following status: [FAILED] in 455ms
ããŒã«ããã¯ãããããã§ãã
ããŒã¿ã
mysql> select * from book; +----------------+---------------------------------------------------------------------------------------------------------+-------+ | isbn | title | price | +----------------+---------------------------------------------------------------------------------------------------------+-------+ | 978-1484237236 | The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud | 7361 | | 978-1492076988 | Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications | 6265 | | 978-4774182179 | [æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ã㣠| 4180 | | 978-4797393118 | åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº) | 6038 | | 978-4798142470 | Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº | 4400 | | 978-4798161488 | MySQL培åºå ¥é 第4ç MySQL 8.0å¯Ÿå¿ | 4180 | +----------------+---------------------------------------------------------------------------------------------------------+-------+ 6 rows in set (0.00 sec)
äž¡æ¹ãšãããŒã«ããã¯ããŸãããããã£ã±ãã¹ã¿ãã¯ãã¬ãŒã¹ãå€ãããŸãããã
RuntimeException
ã®å Žåã
2022-05-27 01:29:24.461 DEBUG 21982 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:29:24.465 DEBUG 21982 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:13) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:5) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor$$FastClassBySpringCGLIB$$775ca5c7.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] ãçç¥ã
Exception
ã®å Žåã
2022-05-27 01:30:48.083 DEBUG 22148 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for Exception: java.lang.Exception: Oops!! 2022-05-27 01:30:48.088 DEBUG 22148 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.Exception: Oops!! at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:487) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] ãçç¥ã Caused by: java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:14) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor.process(BookItemProcessor.java:5) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemProcessor$$FastClassBySpringCGLIB$$775ca5c7.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] ãçç¥ã
ItemProcessor
ã®å Žåã¯ãException
ã®ã¡ãã»ãŒãžãå€ãã£ãŠãããException
ã«ããããŒã«ããã¯ããããšã«ãªã£ãŠããŸãã
2022-05-27 01:30:48.083 DEBUG 22148 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for Exception: java.lang.Exception: Oops!! 2022-05-27 01:30:48.088 DEBUG 22148 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.Exception: Oops!! at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:487) ~[spring-batch-core-4.3.6.jar!/:4.3.6]
ãããŠãUncheckedTransactionException
ãã¹ããŒããããšã«ãªã£ãŠããŸãã
ItemProcessor
ãäŸå€ãããå Žåã§ããRuntimeException
ãException
ã®äž¡æ¹ã§ããŒã«ããã¯ããããšãããããŸããã
ItemProcessor
ã¯ãå
ã«æ»ããŠãããŸãã
@Override public Book process(Book item) throws Exception { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } return item; }
ItemWriterãäŸå€ãã¹ããŒããå Žå
ãã£ã³ã¯ã®æåŸã¯ãItemWriter
ã§ãã
RuntimeException
ãã¹ããŒããŸãã
@Override public void write(List<? extends Book> items) throws Exception { for (Book book : items) { currentCount++; if (currentCount > 7) { throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } entityManager.persist(book); entityManager.flush(); } }
ãã°ã
2022-05-27 01:34:44.319 INFO 22497 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:34:44.666 INFO 22497 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] launched with the following parameters: [{run.id=6}] 2022-05-27 01:34:44.782 INFO 22497 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [chunkStep] 2022-05-27 01:34:44.782 DEBUG 22497 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=6 2022-05-27 01:34:44.987 DEBUG 22497 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:34:44.988 DEBUG 22497 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:34:44.991 DEBUG 22497 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=6, version=1, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=3, filterCount=0, writeCount=3 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription= 2022-05-27 01:34:45.031 DEBUG 22497 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:34:45.032 DEBUG 22497 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:34:45.034 DEBUG 22497 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=6, version=2, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=6, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=0, exitDescription= 2022-05-27 01:34:45.064 DEBUG 22497 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:34:45.064 DEBUG 22497 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:34:45.068 DEBUG 22497 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemWriter.write(BookItemWriter.java:22) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemWriter$$FastClassBySpringCGLIB$$bd3df5e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemWriter$$EnhancerBySpringCGLIB$$37836e73.write(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:193) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:159) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:294) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:217) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:34:45.113 ERROR 22497 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step chunkStep in job chunkJob java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemWriter.write(BookItemWriter.java:22) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemWriter$$FastClassBySpringCGLIB$$bd3df5e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemWriter$$EnhancerBySpringCGLIB$$37836e73.write(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:193) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:159) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:294) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:217) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:34:45.118 INFO 22497 --- [ main] o.s.batch.core.step.AbstractStep : Step: [chunkStep] executed in 334ms 2022-05-27 01:34:45.164 DEBUG 22497 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=6, version=4, name=chunkStep, status=FAILED, exitStatus=FAILED, readCount=9, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=1 2022-05-27 01:34:45.274 INFO 22497 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] completed with the following parameters: [{run.id=6}] and the following status: [FAILED] in 470ms
ããŒã«ããã¯ããŠããŸãã
2022-05-27 01:34:45.064 DEBUG 22497 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:34:45.068 DEBUG 22497 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookItemWriter.write(BookItemWriter.java:22) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemWriter$$FastClassBySpringCGLIB$$bd3df5e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] ãçç¥ã
ããŒã¿ããã¯ãããã£ã³ã¯2ã€åã§ãã
mysql> select * from book; +----------------+---------------------------------------------------------------------------------------------------------+-------+ | isbn | title | price | +----------------+---------------------------------------------------------------------------------------------------------+-------+ | 978-1484237236 | The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud | 7361 | | 978-1492076988 | Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications | 6265 | | 978-4774182179 | [æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ã㣠| 4180 | | 978-4797393118 | åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº) | 6038 | | 978-4798142470 | Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº | 4400 | | 978-4798161488 | MySQL培åºå ¥é 第4ç MySQL 8.0å¯Ÿå¿ | 4180 | +----------------+---------------------------------------------------------------------------------------------------------+-------+ 6 rows in set (0.00 sec)
Exception
ãã¹ããŒããŠã¿ãŸãã
@Override public void write(List<? extends Book> items) throws Exception { for (Book book : items) { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); throw new Exception("Oops!!"); } entityManager.persist(book); entityManager.flush(); } }
ãã°ã
2022-05-27 01:36:02.283 INFO 22698 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:36:02.598 INFO 22698 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] launched with the following parameters: [{run.id=7}] 2022-05-27 01:36:02.715 INFO 22698 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [chunkStep] 2022-05-27 01:36:02.715 DEBUG 22698 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=7 2022-05-27 01:36:02.920 DEBUG 22698 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:36:02.920 DEBUG 22698 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:36:02.923 DEBUG 22698 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=7, version=1, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=3, filterCount=0, writeCount=3 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription= 2022-05-27 01:36:02.958 DEBUG 22698 --- [ main] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false 2022-05-27 01:36:02.958 DEBUG 22698 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=3, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:36:02.960 DEBUG 22698 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=7, version=2, name=chunkStep, status=STARTED, exitStatus=EXECUTING, readCount=6, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=0, exitDescription= 2022-05-27 01:36:02.990 DEBUG 22698 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=3, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:36:02.990 DEBUG 22698 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for Exception: java.lang.Exception: Oops!! 2022-05-27 01:36:02.995 DEBUG 22698 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.Exception: Oops!! at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:487) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] Caused by: java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookItemWriter.write(BookItemWriter.java:23) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemWriter$$FastClassBySpringCGLIB$$bd3df5e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemWriter$$EnhancerBySpringCGLIB$$e1ee2674.write(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:193) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:159) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:294) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:217) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] ... 46 common frames omitted 2022-05-27 01:36:03.011 ERROR 22698 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step chunkStep in job chunkJob java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookItemWriter.write(BookItemWriter.java:23) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookItemWriter$$FastClassBySpringCGLIB$$bd3df5e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookItemWriter$$EnhancerBySpringCGLIB$$e1ee2674.write(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:193) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:159) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:294) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:217) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:77) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:36:03.014 INFO 22698 --- [ main] o.s.batch.core.step.AbstractStep : Step: [chunkStep] executed in 299ms 2022-05-27 01:36:03.068 DEBUG 22698 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=7, version=4, name=chunkStep, status=FAILED, exitStatus=FAILED, readCount=9, filterCount=0, writeCount=6 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=1 2022-05-27 01:36:03.102 INFO 22698 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=chunkJob]] completed with the following parameters: [{run.id=7}] and the following status: [FAILED] in 448ms
ããŒã«ããã¯ããããã§ãã
ããŒã¿ã
mysql> select * from book; +----------------+---------------------------------------------------------------------------------------------------------+-------+ | isbn | title | price | +----------------+---------------------------------------------------------------------------------------------------------+-------+ | 978-1484237236 | The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud | 7361 | | 978-1492076988 | Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications | 6265 | | 978-4774182179 | [æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ã㣠| 4180 | | 978-4797393118 | åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº) | 6038 | | 978-4798142470 | Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº | 4400 | | 978-4798161488 | MySQL培åºå ¥é 第4ç MySQL 8.0å¯Ÿå¿ | 4180 | +----------------+---------------------------------------------------------------------------------------------------------+-------+ 6 rows in set (0.00 sec)
ItemWriter
ã®å Žåã¯ãItemProcessor
ãšåæ§ã«Exception
ãšããŠããŒã«ããã¯ããŠããããã§ãã
2022-05-27 01:36:02.990 DEBUG 22698 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for Exception: java.lang.Exception: Oops!! 2022-05-27 01:36:02.995 DEBUG 22698 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.Exception: Oops!! at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:487) ~[spring-batch-core-4.3.6.jar!/:4.3.6] ãçç¥ã
UncheckedTransactionException
ã«ã©ãããããŠããã®ãåãããã§ããã
ããã§ãItemWriter
ã®å Žåãã¹ããŒãããäŸå€ãException
ãRuntimeException
ãåããããŒã«ããã¯ãããããšãããããŸããã
ItemWriter
ã®ãœãŒã¹ã³ãŒãã¯ãå
ã«æ»ããŠãããŸãã
@Override public void write(List<? extends Book> items) throws Exception { for (Book book : items) { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } entityManager.persist(book); entityManager.flush(); } }
Tasklet
ãã£ã³ã¯ã®æ¬¡ã¯ãTasklet
ãèŠãŠãããŸãã
Tasklet
ã®ãœãŒã¹ã³ãŒãã¯ããã¡ãã
src/main/java/org/littlewings/spring/batch/BookTasklet.java
package org.littlewings.spring.batch; import java.util.List; import javax.persistence.EntityManager; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.Tasklet; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.beans.factory.annotation.Autowired; public class BookTasklet implements Tasklet { @Autowired EntityManager entityManager; @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { List<Book> books = List.of( Book.create("978-4798142470", "Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº", 4400), Book.create("978-4774182179", "[æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ãã£", 4180), Book.create("978-1492076988", "Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications", 6265), Book.create("978-1484237236", "The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud", 7361), Book.create("978-4798161488", "MySQL培åºå ¥é 第4ç MySQL 8.0察å¿", 4180), Book.create("978-4797393118", "åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº)", 6038), Book.create("978-4873116389", "å®è·µãã€ããã©ãŒãã³ã¹MySQL 第3ç", 5280), Book.create("978-4295000198", "ããããåŠã¹ãMySQLéçšã»ç®¡çå ¥éã5.7察å¿ã", 2860), Book.create("978-4798147406", "詳解MySQL 5.7 æ¢ãŸãã¬é²åã«ä¹ãé ããªãããã®ãã¯ãã«ã«ã¬ã€ã (NEXT ONE)", 3960), Book.create("978-4774170206", "MariaDB&MySQLå šæ©èœãã€ãã«", 3860) ); int currentCount = 0; for (Book book : books) { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } entityManager.persist(book); entityManager.flush(); } return RepeatStatus.FINISHED; } }
10ä»¶ã®æžç±ããŒã¿ãã1ä»¶ãã€åæ ããŸãã
Tasklet
ããã£ã³ã¯ã®æãšåæ§ã7ä»¶ç®ã®ããŒã¿ãæ±ããšããã§ã³ã¡ã³ãã¢ãŠããè§£é€ãããšäŸå€ãã¹ããŒããããã«ãªã£ãŠããŸãã
RuntimeException
ããã³Exception
ã§ãã
if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); }
ãã¡ãããã®ã³ã¡ã³ãã¢ãŠãã®è§£é€ãå€åããã€ã€ãã©ã®ãããªåããããããèŠãŠãããŸãã
Job
ã®å®çŸ©ã¯ãã¡ãã
src/main/java/org/littlewings/spring/batch/TaskletJobConfig.java
package org.littlewings.spring.batch; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepScope; import org.springframework.batch.core.launch.support.RunIdIncrementer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class TaskletJobConfig { @Bean public Job taskletJob(JobBuilderFactory jobBuilderFactory) { return jobBuilderFactory .get("taskletJob") .incrementer(new RunIdIncrementer()) .start(taskletStep(null)) .build(); } @Bean public Step taskletStep(StepBuilderFactory stepBuilderFactory) { return stepBuilderFactory .get("taskletStep") .tasklet(bookTasklet()) .build(); } @Bean @StepScope public BookTasklet bookTasklet() { return new BookTasklet(); } }
確èªã¯ããã£ã³ã¯ãšåãããã«ãœãŒã¹ã³ãŒãã倿Žãã€ã€ããã±ãŒãžã³ã°ããŠ
$ mvn package
Job
ãæå®ããŠå®è¡ããããšã«ããŸãã
$ java -Dspring.batch.job.names=taskletJob -jar target/batch-transaction-0.0.1-SNAPSHOT.jar
æ£åžžã«çµäºããå Žå
ãŸãã¯ãæ£åžžã«çµäºããå Žåããã
å®è¡æã®ãã°ã¯ããã¡ãã
2022-05-27 01:37:47.923 INFO 22877 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:37:48.192 INFO 22877 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=taskletJob]] launched with the following parameters: [{run.id=1}] 2022-05-27 01:37:48.373 INFO 22877 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [taskletStep] 2022-05-27 01:37:48.373 DEBUG 22877 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=8 2022-05-27 01:37:48.543 DEBUG 22877 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=0, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:37:48.546 DEBUG 22877 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=8, version=1, name=taskletStep, status=STARTED, exitStatus=EXECUTING, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription= 2022-05-27 01:37:48.573 DEBUG 22877 --- [ main] o.s.batch.core.step.AbstractStep : Step execution success: id=8 2022-05-27 01:37:48.582 INFO 22877 --- [ main] o.s.batch.core.step.AbstractStep : Step: [taskletStep] executed in 208ms 2022-05-27 01:37:48.609 DEBUG 22877 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=8, version=3, name=taskletStep, status=COMPLETED, exitStatus=COMPLETED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0 2022-05-27 01:37:48.637 INFO 22877 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=taskletJob]] completed with the following parameters: [{run.id=1}] and the following status: [COMPLETED] in 390ms
ããŒã¿ã
mysql> select * from book; +----------------+---------------------------------------------------------------------------------------------------------+-------+ | isbn | title | price | +----------------+---------------------------------------------------------------------------------------------------------+-------+ | 978-1484237236 | The Definitive Guide to Spring Batch: Modern Finite Batch Processing in the Cloud | 7361 | | 978-1492076988 | Spring Boot: Up and Running: Building Cloud Native Java and Kotlin Applications | 6265 | | 978-4295000198 | ããããåŠã¹ãMySQLéçšã»ç®¡çå ¥éã5.7察å¿ã | 2860 | | 978-4774170206 | MariaDB&MySQLå šæ©èœãã€ãã« | 3860 | | 978-4774182179 | [æ¹èšæ°ç]Springå ¥é ââJavaãã¬ãŒã ã¯ãŒã¯ã»ããè¯ãèšèšãšã¢ãŒããã¯ã㣠| 4180 | | 978-4797393118 | åºç€ããã®MySQL 第3ç (åºç€ããã·ãªãŒãº) | 6038 | | 978-4798142470 | Spring培åºå ¥é Spring Frameworkã«ããJavaã¢ããªã±ãŒã·ã§ã³éçº | 4400 | | 978-4798147406 | 詳解MySQL 5.7 æ¢ãŸãã¬é²åã«ä¹ãé ããªãããã®ãã¯ãã«ã«ã¬ã€ã (NEXT ONE) | 3960 | | 978-4798161488 | MySQL培åºå ¥é 第4ç MySQL 8.0å¯Ÿå¿ | 4180 | | 978-4873116389 | å®è·µãã€ããã©ãŒãã³ã¹MySQL 第3ç | 5280 | +----------------+---------------------------------------------------------------------------------------------------------+-------+ 10 rows in set (0.00 sec)
TaskletãäŸå€ãã¹ããŒããå Žå
ã§ã¯ãäŸå€ãã¹ããŒããããã«ããŠåäœç¢ºèªããŠã¿ãŸãã
ãŸãã¯RuntimeException
ãã¹ããŒããŠã¿ãŸãã
for (Book book : books) { currentCount++; if (currentCount > 7) { throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } entityManager.persist(book); entityManager.flush(); }
ãã°ã
2022-05-27 01:39:52.695 INFO 23081 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:39:53.006 INFO 23081 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=taskletJob]] launched with the following parameters: [{run.id=2}] 2022-05-27 01:39:53.140 INFO 23081 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [taskletStep] 2022-05-27 01:39:53.140 DEBUG 23081 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=9 2022-05-27 01:39:53.320 DEBUG 23081 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=0, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:39:53.320 DEBUG 23081 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:39:53.326 DEBUG 23081 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookTasklet.execute(BookTasklet.java:37) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookTasklet$$FastClassBySpringCGLIB$$1150977e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookTasklet$$EnhancerBySpringCGLIB$$54aa2694.execute(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:39:53.363 ERROR 23081 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step taskletStep in job taskletJob java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookTasklet.execute(BookTasklet.java:37) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookTasklet$$FastClassBySpringCGLIB$$1150977e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookTasklet$$EnhancerBySpringCGLIB$$54aa2694.execute(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:39:53.369 INFO 23081 --- [ main] o.s.batch.core.step.AbstractStep : Step: [taskletStep] executed in 229ms 2022-05-27 01:39:53.410 DEBUG 23081 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=9, version=2, name=taskletStep, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=1 2022-05-27 01:39:53.441 INFO 23081 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=taskletJob]] completed with the following parameters: [{run.id=2}] and the following status: [FAILED] in 384ms
ããŒã«ããã¯ããŠããŸãã
2022-05-27 01:39:53.320 DEBUG 23081 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:39:53.326 DEBUG 23081 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookTasklet.execute(BookTasklet.java:37) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookTasklet$$FastClassBySpringCGLIB$$1150977e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] ãçç¥ã
Tasklet
ã®å Žåã¯ãã©ã³ã¶ã¯ã·ã§ã³ã¯ã²ãšã€ãªã®ã§ããã¹ãŠã®ããŒã¿ãããŒã«ããã¯ããŸãããã
mysql> select * from book; Empty set (0.00 sec)
Exception
ãã¹ããŒããŠã¿ãŸãã
for (Book book : books) { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); throw new Exception("Oops!!"); } entityManager.persist(book); entityManager.flush(); }
ãã°ã
2022-05-27 01:41:41.628 INFO 23266 --- [ main] o.s.b.a.b.JobLauncherApplicationRunner : Running default command line with: [] 2022-05-27 01:41:41.962 INFO 23266 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=taskletJob]] launched with the following parameters: [{run.id=3}] 2022-05-27 01:41:42.092 INFO 23266 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [taskletStep] 2022-05-27 01:41:42.093 DEBUG 23266 --- [ main] o.s.batch.core.step.AbstractStep : Executing: id=10 2022-05-27 01:41:42.254 DEBUG 23266 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=0, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING] 2022-05-27 01:41:42.255 DEBUG 23266 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for Exception: java.lang.Exception: Oops!! 2022-05-27 01:41:42.260 DEBUG 23266 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.Exception: Oops!! at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:487) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] Caused by: java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookTasklet.execute(BookTasklet.java:38) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookTasklet$$FastClassBySpringCGLIB$$1150977e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookTasklet$$EnhancerBySpringCGLIB$$54aa2694.execute(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] ... 46 common frames omitted 2022-05-27 01:41:42.288 ERROR 23266 --- [ main] o.s.batch.core.step.AbstractStep : Encountered an error executing step taskletStep in job taskletJob java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookTasklet.execute(BookTasklet.java:38) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookTasklet$$FastClassBySpringCGLIB$$1150977e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:137) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.littlewings.spring.batch.BookTasklet$$EnhancerBySpringCGLIB$$54aa2694.execute(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:407) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:152) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:413) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:320) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:149) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.20.jar!/:5.3.20] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.20.jar!/:5.3.20] at jdk.proxy2/jdk.proxy2.$Proxy83.run(Unknown Source) ~[na:na] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.execute(JobLauncherApplicationRunner.java:199) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.executeLocalJobs(JobLauncherApplicationRunner.java:173) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.launchJobFromProperties(JobLauncherApplicationRunner.java:160) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:155) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner.run(JobLauncherApplicationRunner.java:150) ~[spring-boot-autoconfigure-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:752) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar!/:2.7.0] at org.littlewings.spring.batch.App.main(App.java:11) ~[classes!/:0.0.1-SNAPSHOT] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na] at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na] at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[batch-transaction-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT] 2022-05-27 01:41:42.297 INFO 23266 --- [ main] o.s.batch.core.step.AbstractStep : Step: [taskletStep] executed in 203ms 2022-05-27 01:41:42.362 DEBUG 23266 --- [ main] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=10, version=2, name=taskletStep, status=FAILED, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=1 2022-05-27 01:41:42.411 INFO 23266 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=taskletJob]] completed with the following parameters: [{run.id=3}] and the following status: [FAILED] in 377ms
ããŒã«ããã¯ããŸããã
2022-05-27 01:41:42.260 DEBUG 23266 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.Exception: Oops!! at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:487) ~[spring-batch-core-4.3.6.jar!/:4.3.6] ãçç¥ã
ãã£ã³ã¯ã®æãšåãããã«ãUncheckedTransactionException
ã«ã©ãããããŠã¹ããŒãããŠããŸãããããŒã«ããã¯ã®çç±ã«ã€ããŠã¯
Exception
ãšããŠæ±ã£ãŠããŸããã
ããŒã¿ãããŒã«ããã¯ãããŠããŸãã
mysql> select * from book; Empty set (0.00 sec)
RuntimeException
ãšException
ã®ã¹ã¿ãã¯ãã¬ãŒã¹ãã¡ãã£ãšæ¯èŒã
RuntimeException
ã
2022-05-27 01:39:53.320 DEBUG 23081 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: java.lang.RuntimeException: Oops!! 2022-05-27 01:39:53.326 DEBUG 23081 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception java.lang.RuntimeException: Oops!! at org.littlewings.spring.batch.BookTasklet.execute(BookTasklet.java:37) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookTasklet$$FastClassBySpringCGLIB$$1150977e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] ãçç¥ã
Exception
ã
2022-05-27 01:41:42.255 DEBUG 23266 --- [ main] o.s.batch.core.step.tasklet.TaskletStep : Rollback for Exception: java.lang.Exception: Oops!! 2022-05-27 01:41:42.260 DEBUG 23266 --- [ main] o.s.t.support.TransactionTemplate : Initiating transaction rollback on application exception org.springframework.batch.core.step.tasklet.UncheckedTransactionException: java.lang.Exception: Oops!! at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:487) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:331) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.20.jar!/:5.3.20] at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:273) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:82) ~[spring-batch-core-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:375) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:145) ~[spring-batch-infrastructure-4.3.6.jar!/:4.3.6] at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:258) ~[spring-batch-core-4.3.6.jar!/:4.3.6] ãçç¥ã Caused by: java.lang.Exception: Oops!! at org.littlewings.spring.batch.BookTasklet.execute(BookTasklet.java:38) ~[classes!/:0.0.1-SNAPSHOT] at org.littlewings.spring.batch.BookTasklet$$FastClassBySpringCGLIB$$1150977e.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT] at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.20.jar!/:5.3.20] ãçç¥ã
ããã§ãTasklet
ã®å Žåãã¹ããŒãããäŸå€ãRuntimeException
ã§ãã£ãŠãException
ã§ãã£ãŠãããŒã«ããã¯ãããããšãããããŸãããã
ãœãŒã¹ã³ãŒãã¯ãå ã«æ»ããŠãããŸãã
for (Book book : books) { currentCount++; if (currentCount > 7) { // throw new RuntimeException("Oops!!"); // throw new Exception("Oops!!"); } entityManager.persist(book); entityManager.flush(); }
å°ã远ã£ãŠã¿ã
ãããŸã§èŠãŠããŠãåèŠçŽ ããException
ãã¹ããŒãããå Žåã¯ãRepeatException
ãŸãã¯UncheckedTransactionException
ã«ã©ãããããŠ
å床ã¹ããŒãããããšãããããŸããã
ãŸãããã®æã®ItemProcessor
ãItemWriter
ãTasklet
ã®ã¹ã¿ãã¯ãã¬ãŒã¹ã¯ãã¹ãŠåãã§ãããã©ãããããäŸå€ã
UncheckedTransactionException
ã§ããItemReader
ã ãç°ãªããã©ãããããäŸå€ã¯RepeatException
ã§ããã
ããã§å°ããSpring Batchã®å®è£ ãèŠãŠã¿ãŸãããã
ItemReader
ã§äŸå€ãæ±ã£ãŠããïŒåã¹ããŒããŠããïŒã®ã¯ããã¡ãã§ããã
Error
ãRuntimeException
ãException
ãããããèŠãŠããŸããException
ã®å Žåã¯ãRepeatException
ãšããäŸå€ã§ã©ããããŠ
åã¹ããŒã§ããã
ItemProcessor
ãItemWriter
ãTasklet
ã®å Žåã¯ãã¡ãã
Error
ãRuntimeException
ãException
ãããããèŠãŠããŸããException
ã®å Žåã¯ãUncheckedTransactionException
ãšãã
äŸå€ã«ã©ãããããŠã¹ããŒãããŸãã
ãããŠããããã®æ§æèŠçŽ ã§ãã£ãŠããRuntimeException
ãException
åãããäŸå€ãã¹ããŒããããããŒã«ããã¯ãããããšã
確èªã§ããŸããããšã
ãŸãšã
Spring Batchã®ãã©ã³ã¶ã¯ã·ã§ã³ç®¡çã§ãã¹ããŒãããäŸå€ãRuntimeException
ãException
ã«é¢ãããããŒã«ããã¯ãããããšã
確èªããŠã¿ãŸããã
ãªããšãªãException
ã§ãããŒã«ããã¯ããã®ã ãããšæã£ãŠããŸããããå®éã«ç¢ºèªããŠãããšå®å¿ããªãšã
Exception
ã®å Žåã¯ãå
éšçã«ã¯å¥ã®äŸå€ã§ã©ãããããŠåã¹ããŒãããŠããããšãããããŸãããã