Search code examples
javaspringhashmapspring-batchlinkedhashmap

Why Spring batch JobParameters using LinkedHashMap


Compared to HashMap, LinkedHashMap guarantees input order.

In Spring Batch, I think HashMap is enough to save JobParameter, but I don't know why JobParameters used LinkedHashMap. What do you think about this?

Below are some of the implementations of JobParameters. Github Link

public class JobParameters implements Serializable {

    private final Map<String,JobParameter> parameters;

    public JobParameters() {
        this.parameters = new LinkedHashMap<>();
    }

    public JobParameters(Map<String,JobParameter> parameters) {
        this.parameters = new LinkedHashMap<>(parameters);
    }

    // ...

Solution

  • There is no ordering between job parameters. The usage of a linked hash map is not justified in my opinion.

    You can open an issue with a link to this SO thread and we will consider changing that in Spring Batch.