Skip to content
Commit aea48a9d authored by David Hoover's avatar David Hoover
Browse files

Synchronize all appropriate methods in ConsistentHash.

Only add(T, int) was synchronized (and its javadoc claimed it was the
only one modifying .items), but all the bulk add methods were going
straight to addInternal() and then refreshTable() on their own. Then
countAllPoints() was iterating over items.values() which has undefined
behavior if the underlying Map changed.

Technically I didn't need to synchronize the current implementations of
remove(T) and add(T) since they delegated fully to add(T, int), but
that's leaking implementation details and inviting trouble down the road
when someone doesn't realize that.

Likewise, addInternal() and refreshTable() need not be synchronized
since they're only ever called from already synchronized methods, but
I'm inclined to go for belt & suspenders in the wake of these other
issues.
parent d7f83ec2
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment