-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Maps changed to ConcurrentHashMaps for SharedExecutorServiceAsyncExecutor #2863
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR.
Can you please explain why we need to use a ConcurrentHashMap
. From what I can see there are 4 places that are iterating the over some of the maps. Only timerJobAcquisitionThreads
and timerJobAcquisitionRunnables
have their key sets iterated.
We could replace those places with a call to getTenantIds
and in that method return a copy of the tenant id in one of the maps.
@filiphr : In our environment (multi tenancy), we are adding new tenants dynamically at runtime which can be done by independent threads. If that happens in parallel for the same tenant, it might lead to several started runnables for the same tenant. Alternatively, we could add a synchronization into the addTenantAsyncExecutor method so that for a given tenant, this cannot be called in parallel. We had a similar situation some time back in #2393 |
Thanks for the explanation @StefanHenke. Knowing your actual problem I do not see how using If we take a look at the Lines 78 to 99 in b3e26a8
We will see that there is no check whether an entry already exists. Therefore, even if the method is synchronized you can still call it twice with the same There are 2 options to actually fix your problem:
e.g.
You can of course have a different logic about this, you could stop the threads if you want to, or you could do something else, entirely up to your custom logic. |
@filiphr : Thanks for looking into this. You are right. Situation here is a bit different to |
Closing the PR for @StefanHenke as he requested. |
Check List:
changed Maps to ConcurrentHashMaps for SharedExecutorServiceAsyncExecutor