Tuesday, September 20, 2022

[FIXED] Why Spring batch JobParameters using LinkedHashMap

Issue

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.



Answered By - Mahmoud Ben Hassine
Answer Checked By - Marilyn (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.