Skip to content

JobParameters should use LinkedHashMap instead of HashMap #4179

Closed
@JinseongHwang

Description

@JinseongHwang

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions