-
Notifications
You must be signed in to change notification settings - Fork 47
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
fix: expand ReentrantLock scope in MonitorThreadContainer for better … #601
fix: expand ReentrantLock scope in MonitorThreadContainer for better … #601
Conversation
2111d9e
to
f5996c3
Compare
Just realized that perhaps using |
84633c0
to
e784af6
Compare
@@ -0,0 +1,68 @@ | |||
/* |
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.
NIT: can we rename it to ConcurrencyEFMTest ?
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.
ConcurrencyEFMTest
may be too general. There is also another pre-existing test class MultiThreadedDefaultMonitorServiceTest
that also tests concurrency in EFM.
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.
Is the nit b/c MultiThreadedMonitorThreadContainerTest
is extremely verbose? :D
I was thinking of replacing MultiThreaded
with Concurrency
so the test class name would be ConcurrencyMonitorTheadContainerTest
but that still seems a bit wordy.
What do you think?
...r/src/test/java/software/amazon/jdbc/plugin/efm/MultiThreadedMonitorThreadContainerTest.java
Outdated
Show resolved
Hide resolved
Instead of using synchronized it would be better to use the re-entrant lock before the first check. synchronized is still a heavier lock. |
f63e6d2
to
05f3fa3
Compare
wrapper/src/main/java/software/amazon/jdbc/plugin/efm/MonitorThreadContainer.java
Show resolved
Hide resolved
b3ee732
to
9c5cb33
Compare
@Mock | ||
ExecutorServiceInitializer mockExecutorServiceInitializer; |
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.
@Mock | |
ExecutorServiceInitializer mockExecutorServiceInitializer; | |
@Mock ExecutorServiceInitializer mockExecutorServiceInitializer; |
@Mock | ||
ExecutorService mockExecutorService; |
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.
@Mock | |
ExecutorService mockExecutorService; | |
@Mock ExecutorService mockExecutorService; |
9c5cb33
to
1a03dfb
Compare
…thread safety
Summary
Remove race condition in
MonitorThreadContainer
betweengetInstance()
andreleaseInstance()
methods.Description
In the
MonitorThreadContainer
, there are possible race conditions between thegetInstance()
andreleaseInstance()
methods.In one of the race conditions is in the
getInstance()
.Just after the lock object is unlocked, is an opportunity for a race condition with another thread in the
releaseInstance()
method.If the locked block is entered, a race condition may result.
getInstance()
may return a nullsingleton
which will be followed by a NPE. Or another scenario is that a non-null singleton will be returned, butsingleton.releaseResources()
is called so theMonitorThreadContainer
'sthreadPool
will be shutdown and subsequent usage of the threadPool will result in aRejectedExecutionException
.Additional Reviewers
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.