AdamaJava / adamajava

Other
14 stars 5 forks source link

multi threading bug in XmlUtils.updateMapWithLimit #333

Open holmeso opened 1 year ago

holmeso commented 1 year ago

Describe the bug The XmlUtils.updateMapWithLimit method attempts to cap the number of entries in a map. However, it is not thread safe, and if multiple threads attempt to insert a new key at the same time, it is possible to get more entries in the map than desired.

This gives non-deterministic results when running multi-threaded apps (eg. qprofiler2)

To Reproduce

Expected behavior It would be great to be able to run qprofiler2 multiple times with multiple threads and get the same result every time

Additional context Is there any reason that the map is being kept to a certain size? If it is just the top 100 entries that are required, would it not be a better approach to capture all the entries, and then sort and report on just the top 100? That way you would get the same results every time.