Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Make PlayerList more thread safe

Open stonar96 opened this issue 4 years ago • 6 comments

This PR makes online player lookups by unique ID and name thread safe, which can be useful for e.g. sending messages in an asynchronous context but it also improves thread safety of various other methods that do player lookups internally, such as some methods of OfflinePlayer.

Although visibility is often no issue because of a present happens-before relationship and I have heard several times that concurrent reads are fail-safe in the most HashMap implementations nowadays, the docs do not guarantee any behavior regarding this. Therefore I have replaced the HashMaps by ConcurrentHashMaps.

Note that HashMap and ConcurrentHashMap have different contracts for null keys, which also affects behavior of API methods. However, those are all annotated with @NotNull anyway and no null keys are used internally as far as I can see.

I don't know if this has any noticeable effects performance wise.

stonar96 avatar Apr 05 '21 01:04 stonar96

This breaks some plugins, i tested this patch

ghost avatar May 05 '21 03:05 ghost

can you give any concrete details?

zml2008 avatar May 05 '21 04:05 zml2008

Rebased, updated and tested.

stonar96 avatar Jun 25 '21 02:06 stonar96

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 24 '21 03:08 stale[bot]

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 11 '21 01:11 stale[bot]

Rebased and tested.

stonar96 avatar Nov 30 '21 23:11 stonar96

Seeing as though there hasn't been much activity on this, and there has not been much that warranted a need for this, I will be closing this.

There are in general a lot of places where players can be retrieved, which may be considered "unsafe" when done async, and if you want to access them in an async manner, it would most likely be better to upkeep your own kind of safe collection.

Feel free to leave a comment if you disagree.

Owen1212055 avatar May 18 '23 12:05 Owen1212055