Skip to content

JSON files are randomly not well formatted when multi-thread step is used #4708

@glelarge

Description

@glelarge

Bug description
Spring Batch offers the possibility to configure a chunk-oriented step as multi-threaded by configuring a TaskExecutor in the Step configuration.

When configured with multi-thread, the produced JSON is sometimes not correctly formatted.

Detected with Spring Batch 5.1.2 and Spring Framework 6.1.13.

Wrong result
Sometime the produced JSON is misformatted :

[
,
 {"code":10002,"ref":"B2C3D4E5F6G7","type":11,"nature":6,"etat":2,"ref2":"B2C3D4E5F6G7"} {"code":10001,"ref":"A1B2C3D4E5F6","type":10,"nature":5,"etat":1,"ref2":"A1B2C3D4E5F6"},
 {"code":10003,"ref":"C3D4E5F6G7H8","type":12,"nature":7,"etat":3,"ref2":"C3D4E5F6G7H8"},
 {"code":10004,"ref":"D4E5F6G7H8I9","type":13,"nature":8,"etat":4,"ref2":"D4E5F6G7H8I9"}
]

Expected result

[
 {"code":10001,"ref":"A1B2C3D4E5F6","type":10,"nature":5,"etat":1,"ref2":"A1B2C3D4E5F6"},
 {"code":10002,"ref":"B2C3D4E5F6G7","type":11,"nature":6,"etat":2,"ref2":"B2C3D4E5F6G7"},
 {"code":10003,"ref":"C3D4E5F6G7H8","type":12,"nature":7,"etat":3,"ref2":"C3D4E5F6G7H8"},
 {"code":10004,"ref":"D4E5F6G7H8I9","type":13,"nature":8,"etat":4,"ref2":"D4E5F6G7H8I9"}
]

When the file is not well formatted, the error is always the same :

  • a single comma appears at the first line
  • the second line contains 2 JSON records without separator

Minimal Complete Reproducible example

https://github.com/glelarge/spring-batch-json-multithread

git clone https://github.com/glelarge/spring-batch-json-multithread
cd spring-batch-json-multithread
mvn package
./run.sh

If the issue is related to the configuration, would it be possible to update the repo to fix the configuration ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    has: minimal-exampleBug reports that provide a minimal complete reproducible exampletype: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions