-
Notifications
You must be signed in to change notification settings - Fork 1.1k
First pass - trivial synchronized blocks #8652
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
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.
Mostly this is OK, but really too much and it is easy to miss something.
Please, see if you really were right about changing tryLock()
to lock()
everywhere you found it.
as we already know this is easier to review with ?w=1
.
@tzolov ,
let's see next time if can propose the change in baby steps, per use-case. Really hard to review.
if (name == null) { | ||
name = this.applicationContext.getEnvironment().getProperty("spring.application.name"); | ||
private Graph buildGraph() { | ||
this.lock.lock(); |
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.
May we have this optimized like call this.lock.lock()
only once?
What I mean we probably need to extract a private Graph doBuildGraph()
without lock and have it called from this buildGraph()
surrounded with lock and also call it from that getGraph()
.
Right now we from that getGraph()
we have two this.lock.lock()
.
Although it might be just my paranoia and that is not a big deal since we would have just increased count on the lock.
And that it, you know, why huge PRs are not OK, when they touch a lot of not related stuff 🤷
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.
Technically it should work as it is given the preemtive nature of the locks.
But looking at the getGraph() it seems like the mutex is redundat there. I belive something like this should be correct:
public Graph getGraph() {
if (this.graph == null) {
buildGraph(); // already under mutex
}
return this.graph;
}
what do you think?
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.
If several threads call this getGraph()
and encounter with this.graph == null
, they step into that buildGraph()
and wait for a lock
.
When first one is done with building, it releases lock and the next one takes it and start building a fresh graph.
We do that unconditionally in the rebuild()
, but getGraph()
should build only once.
Well, let's leave it as you have in the PR right no and revise it later in the separate change!
...ration-file/src/main/java/org/springframework/integration/file/locking/FileChannelCache.java
Outdated
Show resolved
Hide resolved
...n/java/org/springframework/integration/ip/tcp/connection/CachingClientConnectionFactory.java
Show resolved
Hide resolved
...p/src/main/java/org/springframework/integration/ip/udp/MulticastReceivingChannelAdapter.java
Outdated
Show resolved
Hide resolved
...-ip/src/main/java/org/springframework/integration/ip/udp/MulticastSendingMessageHandler.java
Outdated
Show resolved
Hide resolved
...ration-mqtt/src/main/java/org/springframework/integration/mqtt/core/Mqttv5ClientManager.java
Outdated
Show resolved
Hide resolved
...n/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java
Outdated
Show resolved
Hide resolved
...mqtt/src/main/java/org/springframework/integration/mqtt/outbound/MqttPahoMessageHandler.java
Outdated
Show resolved
Hide resolved
...socket/src/main/java/org/springframework/integration/websocket/ClientWebSocketContainer.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/springframework/integration/zookeeper/config/LeaderInitiatorFactoryBean.java
Outdated
Show resolved
Hide resolved
- Convert the "trivial" synchronized block into reetrant locks. Resolves spring-projects#8643
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.
Just one concern so far I've noticed.
...n/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java
Show resolved
Hide resolved
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.
Looks like the change in STOMP module has affected somehow tests:
StompInboundChannelAdapterWebSocketIntegrationTests > testWebSocketStompClient() FAILED
java.lang.AssertionError at StompInboundChannelAdapterWebSocketIntegrationTests.java:162
It is a bit strange as we have not changed much on the Stomp Inbound channel code.
After qualifying explicitly the taskScheduler : @Bean
public WebSocketStompClient stompClient(@Qualifier("taskScheduler") TaskScheduler taskScheduler) {
... and the @Bean
public ApplicationListener<SessionSubscribeEvent> webSocketEventListener(@Qualifier("clientOutboundChannel") final AbstractSubscribableChannel clientOutboundChannel) {
... The test passes. But i'm no sure if this fixes or masks the core reason that lead to this. |
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.
This is OK with me.
@garyrussell ,
let us know if you are going to review it, or just let it go and come back to specific concern when it raises!
I don't see a need for me to review. Thanks. |
Then I'll merge this as is and we can revise other concerns in other PRs or so. |
Resolves #8643