Results 1 to 5 of 5

Thread: What is best practices for skipping the remaining job from a tasklet?

Hybrid View

  1. #1
    Join Date
    Oct 2008
    Posts
    3

    Question What is best practices for skipping the remaining job from a tasklet?

    I'm considering strategies for a simple batch line, which starts with checking a drop directory. Only if a new file is found should the rest of the steps proceed and an item reader (file) resource need to be injected.

    I'm considering either of these two alternatives:
    Alt 1) Perform directory polling outside SpingBatch and launch a job only if a file is found.
    Alt 2) Implement directory scan as a tasklet and cancel the job if no file is found.

    The problem with alt 2 is that throwing an exception causes the job to fail and results in a restart. The SkipLimitStepFactoryBean class is item oriented and is not suited for a tasklet doing directory scanning.

    Question 1) Has anybody experience of something similar and would like to share lessons learned?
    Question 2) Besides of implementing directory scanning myself, are there any good libraries that work nicely with SpringBatch? I have found JPoller, but it seems abandoned and not present in any Maven repo (mvnrepository).

    /jens

  2. #2
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    I'd suggest that the directory checking is not part of the spring batch 'workflow'. That's how I've implemented it.

    Note that detecting a file drop is functionally equivilent to having a timer fire; these things are outside the purview of Spring Batch.

    So, you have some timer that periodically checks a directory for a new file. If one is found, the batch job is kicked off with the file as input, otherwise the timer goes back to sleep. Capice?

  3. #3
    Join Date
    Oct 2008
    Posts
    3

    Default

    Quote Originally Posted by chudak View Post
    I'd suggest that the directory checking is not part of the spring batch 'workflow'. That's how I've implemented it.

    Note that detecting a file drop is functionally equivilent to having a timer fire; these things are outside the purview of Spring Batch.

    So, you have some timer that periodically checks a directory for a new file. If one is found, the batch job is kicked off with the file as input, otherwise the timer goes back to sleep. Capice?
    Thanks!
    I had a nagging feeling that this was the way to go, after struggling with skip logic configuration.

    Do you have any pointers for directory scanning, besides JPoller or a fresh hack?

    /jens

  4. #4
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    I would check out Spring Integration, I can't remember the classname off the top of my head, but they a form of Message Channel that will poll a directory and turn the File object into a Message, you can then use that to kick off a Spring Batch job by using the File in the JobParameters.

  5. #5
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    Quote Originally Posted by foobar17 View Post
    Thanks!
    I had a nagging feeling that this was the way to go, after struggling with skip logic configuration.

    Do you have any pointers for directory scanning, besides JPoller or a fresh hack?

    /jens
    I wrote my own directory listener several years ago that we are using in several of our projects here. It dispatches to a pluggable listener on file (add/delete/change), has support for regex filename pattern matching and can be triggered using either a java timer or a quartz job.

    Sounds like the spring integration may be better for you so you don't have to reinvent the wheel (SI didn't exist 2 years ago when I had this need). JPoller may work as well (it was a little overkill for my needs IIRC).
    Last edited by chudak; Nov 10th, 2008 at 09:53 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •