-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Update MicronautMetaServiceLoaderUtils.java to fix single threaded service loader #11229 #11326
Conversation
Fix for service loader micronaut-projects#11229 @andriy-dmytruk @graemerocher @dstepanov I believe the change is not complete and still has a logical error. Another way to change the parallelisim would be to set -XX:ActiveProcessorCount. This option is used in dockerized environments to limit resources used by the application. In my tests, wenn I set the option a value smaller than 3 (parallelism is active processor count -1), then micronaut application will not start. I believe the condition to add the services in the class MicronautMetaServiceLoaderUtils (line 260) is not correct: is: if (val != null && predicate != null && !predicate.test(val)) { but should be: if (val != null && !collection.contains(val) && (predicate == null || predicate.test(val))) {
Right, I don't think we need |
@@ -257,7 +257,7 @@ public List<S> collect(boolean allowFork) { | |||
List<S> collection = new ArrayList<>(serviceEntries.size()); | |||
for (String serviceEntry : serviceEntries) { | |||
S val = instantiate(serviceEntry, classLoader); | |||
if (val != null && predicate != null && !predicate.test(val)) { | |||
if (val != null && !collection.contains(val) && (predicate == null || predicate.test(val))) { |
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.
collection.contains(val)
might be a costly operation, so I wonder if it is required. Do the services implement a correct equals method, so that this would actually make a difference?
If it is required,can we use a set instead of a list and don't do this check?
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.
The parallel option has it (line 312)
if (result != null && !values.contains(result)) {
That's why I added it. If the check is not required, I would remove it ... I would prefer to remove it from both places to avoid confusion.
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.
I think we an remove it there
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.
okak, I have committed the change
remove collection.contains as it is expensive operation and not needed
Thanks for the contribution! |
…rvice loader micronaut-projects#11229 (micronaut-projects#11326) Fix for service loader micronaut-projects#11229 I believe the change is not complete and still has a logical error. Another way to change the parallelisim would be to set -XX:ActiveProcessorCount. This option is used in dockerized environments to limit resources used by the application. In my tests, wenn I set the option a value smaller than 3 (parallelism is active processor count -1), then micronaut application will not start. I believe the condition to add the services in the class MicronautMetaServiceLoaderUtils (line 260) is not correct: is: ``` if (val != null && predicate != null && !predicate.test(val)) { ``` but should be: ``` if (val != null && !collection.contains(val) && (predicate == null || predicate.test(val))) { ```
Fix for service loader #11229
@andriy-dmytruk @graemerocher @dstepanov
I believe the change is not complete and still has a logical error. Another way to change the parallelisim would be to set -XX:ActiveProcessorCount. This option is used in dockerized environments to limit resources used by the application.
In my tests, wenn I set the option a value smaller than 3 (parallelism is active processor count -1), then micronaut application will not start.
I believe the condition to add the services in the class MicronautMetaServiceLoaderUtils (line 260) is not correct:
is:
if (val != null && predicate != null && !predicate.test(val)) {
but should be:
if (val != null && !collection.contains(val) && (predicate == null || predicate.test(val))) {