Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple Spring Batch

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to setup a simple Spring Batch which runs every hour within the container and checks for a table flag and makes an insert into another table.

Whats the easiest way to start ? Couldn't find a simple example for Spring batch within the web container.
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather, I am not sure I have to run it within the container. I want the batch code to be a part of the ear but how do I trigger it ?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked out the Spring Batch documentation. Yes, I know a RTM post. But actually the Spring Batch documentation is the best documentation I have found for all of Spring modules. It is really an easy read and explains everything.

You can choose to run in a container or not, it runs anywhere, just like anything from Spring. Well, except Spring MVC requires something with a web container, ;)

Mark
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read the docs and thought the first step would be to call a job inside an existing @Service.



I get the following exception


How do I define this ?
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed it


But now I get the following exception. I don't want to store any meta-data "initially" since the application tables track it. How can I go about it without creating the batch tables

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, fixed that also. Ran the DDLs @ http://static.springsource.org/spring-batch/reference/html/metaDataSchema.html

I get the following exception

when I run


What is the right way to trigger the job and have it run by the hour.
 
Rishi Shehrawat
Ranch Hand
Posts: 218
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case a job has already executed successfully OR is already running, Spring throws an exception. From the names of the readers & writers it seems like they are running in an infinite loop. So when Spring tries to launch a new instance the previous one is already running, so it throws an exception.

In your case even if the previous job had finished running the next one will still fail as you are passing same job parameters. For each job instance you need to pass different job parameters. In case you don't have any parameters for the job you can use the JobParametersIncrementer to create uniqueness.

For scheduling the task every hour you can use the task namespace provided by Spring. You can write a bean to start a job & scheduler to trigger/invoke method of the bean.

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rishi, I was able to get the scheduling to work


What you said makes sense, the job might be still running but what surprises me is that log messages placed in both files ain't displayed so it seems like they are never called. Need to try harder to figure this out.

Here goes the InfiniteLoopWriter and InfiniteLoopReader from the Spring samples just in case.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic