Skip to content

Optimize synchronized in PartitionedDispatcher #8640

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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,16 @@ public boolean dispatch(Message<?> message) {
return partitionDispatcher.dispatch(message);
}

private synchronized void populatedPartitions() {
private void populatedPartitions() {
if (this.partitions.isEmpty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will probably need a // NOSONAR here (and other unsynchronized uses) to prevent Sonar from complaining.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how that suppose to complain since this property is final.
Plus our Sonar instance it out of order for a while.
I'd prefer to look into this when we come back into business with Sonar and it indeed will complain respectively.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think being final matters, I believe Sonar will report a smell for inconsistent synchronization of fields.

for (int i = 0; i < this.partitionCount; i++) {
this.partitions.put(i, newPartition());
synchronized (this.partitions) {
if (this.partitions.isEmpty()) {
Map<Integer, UnicastingDispatcher> partitionsToUse = new HashMap<>();
for (int i = 0; i < this.partitionCount; i++) {
partitionsToUse.put(i, newPartition());
}
this.partitions.putAll(partitionsToUse);
}
}
}
}
Expand Down