Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Writing data to Multiple file

  1. #11
    Join Date
    Feb 2008
    Posts
    488

    Default

    There is no bug. This is a common use case. Can you post your revised code?

  2. #12
    Join Date
    May 2009
    Posts
    21

    Default

    Quote Originally Posted by DHGarrette View Post
    There is no bug. This is a common use case. Can you post your revised code?
    Please find attached snippet of modified writer. I have configured batch in order to have 1 writer and print only AttribA list. But my requirement is each List of AttribA should get printed in separate output file. But still i am getting same message 'Item strean already closed...........'
    Attached Files Attached Files

  3. #13
    Join Date
    Feb 2008
    Posts
    488

    Default

    You need to get rid of the CompositeItemStream stuff. The CompositeItemStream is trying to manage your FFIW for you. However, this is not what you want. Inside your write() method you are manually opening and closing the FFIW. You do not want the framework to try to open/update/close the FFIW.

  4. #14
    Join Date
    May 2009
    Posts
    21

    Default

    Quote Originally Posted by DHGarrette View Post
    You need to get rid of the CompositeItemStream stuff. The CompositeItemStream is trying to manage your FFIW for you. However, this is not what you want. Inside your write() method you are manually opening and closing the FFIW. You do not want the framework to try to open/update/close the FFIW.
    My main intention to open and close the FFIW is to make sure each and every time a new file is getting generated. is there any other way to achieve the same.

  5. #15
    Join Date
    Feb 2008
    Posts
    488

    Default

    That's exactly what the code sample I provided before will do. It is saying that for each item, create a new FFIW, set a new resource (with a new filename), open it, write to it, and close it. All of which is handled in the write() method.

  6. #16
    Join Date
    May 2009
    Posts
    21

    Default

    Quote Originally Posted by DHGarrette View Post
    You need to get rid of the CompositeItemStream stuff. The CompositeItemStream is trying to manage your FFIW for you. However, this is not what you want. Inside your write() method you are manually opening and closing the FFIW. You do not want the framework to try to open/update/close the FFIW.
    There is a bit progress. Now i am not getting mesage 'Stream already closed' because now i am creating reference of FileItemWriter in the write() method itself, opening it, writing data to it and then closing it.
    Is there a way by which CompositeItemStream can be used to write multiple files where opening/closing of FFIW is managed by framework itself. Each and every time CompanyDTO object comes to the writer a new file should get created.

  7. #17
    Join Date
    Feb 2008
    Posts
    488

    Default

    Using ItemStream to have the framework manage opening/closing is the standard way to use Spring Batch. However, this does not apply to your situation. The reason is because the scope of your file is smaller than the write() method. Since you must open and close more than one file within one call to write() there is no way that the framework could do it for you. But you should not consider this to be a problem; you simply have different requirements than the typical batch job.

Posting Permissions

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