aspose file tools*
The moose likes Spring and the fly likes Simple Spring Batch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Simple Spring Batch" Watch "Simple Spring Batch" New topic
Author

Simple Spring Batch

Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
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

Joined: May 28, 2008
Posts: 183
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jay Abrahm
Ranch Hand

Joined: May 28, 2008
Posts: 183
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

Joined: May 28, 2008
Posts: 183
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

Joined: May 28, 2008
Posts: 183
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

Joined: Aug 11, 2010
Posts: 218

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

Joined: May 28, 2008
Posts: 183
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.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple Spring Batch
 
Similar Threads
Batch Framework in J2EE
Spring Tr
What is a Container ???
org.springframework.batch.core.repository.JobExecutionAlreadyRunningException
Batch Framework in J2EE