spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

Why Spring batch JobParameters using LinkedHashMap

Open JinseongHwang opened this issue 3 years ago • 0 comments

from Stackoverflow

Hi there,

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);
    }

    // ...
}

From what I've looked for, LinkedHashMap is more faster than HashMap in some features. ref Have you decided to use LinkedHashMap simply for the above reasons?

I think, It seems good to use HashMap if ordering is not needed. Using LinkedHashMap seems to have something to do with the order. It can cause misunderstanding.

What do you think about this?

Thanks.

JinseongHwang avatar Aug 23 '22 10:08 JinseongHwang