How to read items from a text file and save in-memory database at regular intervals by Spring Batch?

Tags:
Batch jobs
In-Memory Database
Java
Java programming
I have a situation that I need to read the items from a text file and store in the in-memory database (say HSQLDB). The text file contains 40 lines with a group of 4 items say:
    A : 100
    B : 200
    C : 300
    D : 400
    A : 500
    B : 600
    C : 700
    D : 800
    A : 900
    B : 1000
    C : 1100
    D : 1200
    ....
    ....
    A : 3700
    B : 3800
    C : 3900
    D : 4000
The limit of the text file will be exactly 40 lines. Now, I have to read each group of:
    A : 100
    B : 200
    C : 300
    D : 400
In exactly every one second. Now, this read group has to be pushed to an in-memory database (HSQLDB) but the way it gets persisted is different. There are slots available to persist the values of the group. The elements of C & D should get persisted at every 3rd second and elements A & B should get persisted at every 5th second. So at every 3rd second, all the elements of C & D should get persisted and same goes for elements A&B at every 5th second. By the way, these elements are tickers which are used in Financial industry. I searched a lot for any framework that fits into this and came across Spring Batch. There are in-built Reader and Writer to do such tasks. Also, there is Processor to process the data before getting written by the writer. I looked in the docs of Spring Batch and could not find much help for incorporating my requirement. Though there is `Chunk processing` and `commit interval`. My Questions:
  1. How shall I set the Time interval of every second in the reader?
  2. How the chunk of 4 items to read from the file gets set for every second?
  3. How to set the writer to persist only the elements (A&B) in every 5th second and elements (C&D) in every 3rd second?
My Job configuration in job-config.XML is:
commit-interval="4">
I am completely new to Spring Batch and would appreciate for the quick responses. Thanks,

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: