Results 1 to 4 of 4

Thread: Multiple Threads writing to same report file

  1. #1
    Join Date
    Dec 2008
    Posts
    10

    Default Multiple Threads writing to same report file

    Hi,

    I am using the following task executor

    Code:
    <bean id="taskExecutor"
    		class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    while running my batch appplication it should also be creating report files. How to make the different threads write to a single report file?

    Thanks.

  2. #2

    Default

    What exactly are you writing to the file? You can't really have multiple things having an open session to a file. You could

    a) Throw things at the end of the file with no guarantee of how it will look when it is done
    b) Throw each thread in a separate file, and cat them together at the end


    But both sound suspicious... reports normally can't just be a bunch of different stuff thrown together, normally they have some kind of ordering.... (unless somehow you are making millions of different reports, and you just want them all in 1 file)

  3. #3
    Join Date
    Dec 2008
    Posts
    10

    Default

    The file contains details about the job being run. I am using the partitioning technique with small xml files being processing by each thread. These xmls contains invoice items details.

    I want to be able to write number of items read, processed, fail processing etc. I would ideally want all those threads to write to a common file per job run.

    It is similar to a log file on the server, no matter how many threads are running they all write to a single file. I would like a similar functionality.

  4. #4

    Default

    So if thread A does 5 of something, and thread B does 10 of something.. you want them combined and output into a common file that says 15 things processed?

    I would store the information in some kind of thread safe datastructure (i.e. ConcurrentHashMap). Then pass this guy on to a new step, that is a single threaded tasklet. It can read your stats out of the map, combine them, and then dump to file.

Posting Permissions

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