• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple Spring Batch

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 218
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic