-
Notifications
You must be signed in to change notification settings - Fork 136
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
[Notifications] Replace mutable map with Thread safe map for storing all active notifications #12655
base: trunk
Are you sure you want to change the base?
Conversation
…fy concurrent modification exception is not thrown.
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.
|
@kidinov Converted this to draft as I realised that we need to maintain notification order for displaying it in group notifications and |
I think this may work: |
In this case, we likely need to add a |
Not sure I am following. Why so? |
AFAIU, I could confirm this by changing the notifications map to Let me know if I'm missing something. Thanks! |
My understanding of the documentation is that you need to sync on the map when you are iterating over anything that returned from it, e.g iterator, keys etc Having said that, I looked up the code, and I don't understand where we need an insertion order. Could you please point me out? Also, do you understand why |
and few more
I'm not sure. Maybe for performance gains? |
I tried to change the implementation of the map to
In most cases, there is no performance gain, though, as we just iterate over the map. In a couple of places we filter so it'll give minimal performance, but we probably talking about a few notifications here so probably negletable |
Version |
Version |
Version |
Version |
Version |
Closes: #12654
Description
While fixing
ConcurrencyModificationException
#12646, we came to conclusion that replacingmutableMap
with Thread safe map would benefit in the long run.This PR:
ACTIVE_NOTIFICATIONS_MAP
toactiveNotificationsMap
mutableMap
withConcurrentHashMap
@Synchronized
annotation from public methods inNotificationMessageHandler
ConcurrentModificationException
Testing information
I've tested this by ensuring unit test pass after making this change and fails if we revert this change. Please ensure the notifications flow isn't broken by this change.
activeNotificationsMap
mutableMap fromConcurrentHashMap
handle notifications concurrently without throwing ConcurrentModificationException
unit testactiveNotificationsMap
toConcurrentHashMap
RELEASE-NOTES.txt
if necessary. Use the "[Internal]" label for non-user-facing changes.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: