Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace hashtables with concurrenthashmaps #3488

Merged
merged 1 commit into from
Nov 3, 2019
Merged

Replace hashtables with concurrenthashmaps #3488

merged 1 commit into from
Nov 3, 2019

Conversation

silverwolfg11
Copy link
Contributor

Re-Opened PR of #3486 due to bad merging on my part.

ConcurrentHashMap vs Hashtable

Hashtables are much slower than a normal hashmap. Although they provide thread-safety, they do so at the cost of locking the entire map for reads and writes.
They are also outdated compared to concurrenthashmaps (hashtables were introduced with the original java util, while concurrenthashmaps were introduced in jdk 1.5)

ConcurrentHashMaps are much more efficient because instead of locking the entire map, they lock individual bins. They also do not lock on reads, which makes read-access much faster than a hashtable. Furthermore, they offer thread-safe iteration since they copy the internal data to the iterator.

If that doesn't convince you to use ConcurrentHashMaps, then I don't know what will.

PR Change

This PR simply changes the hashtables within the TownyUniverse class and the hashtable for townblocks within the TownyWorld class to ConcurrentHashMaps.
Regarding ABI changes, with the latest Towny API most of the previous hashtables were only for internal use and not directly accessible by external plugins anyway. Thus the change should not break any external plugins.
I have tested this PR, but non-extensively; I really doubt anything will break anyway.

@LlmDl LlmDl merged commit 2edc1ca into TownyAdvanced:master Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants