-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
lock.lock() before try #7582
lock.lock() before try #7582
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.
looks good
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.
在外面没什么问题。参考:https://juejin.cn/post/7269962653795270671
原写法是写到里面了,这个pr是改到外面的 |
这个回复好像容易误导人。 看下 jdk 的官方文档建议吧,应该来说是最“正宗的”,https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/ReentrantLock.html
另外,上面掘金文章结尾有几句话:
严格来讲这几个结论,可能在 ReentrantLock 这个实现下是没问题的,但 lock 是接口,会有任意实现多种实现。 在不同的实现下,lock.lock() 方法抛出异常是很有可能的,因此不能放在 try 当中。 |
更标准做法,是要放到try外面。 |
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.
LGTM
resolved conflicts |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## develop #7582 +/- ##
=============================================
+ Coverage 43.25% 43.26% +0.01%
- Complexity 9880 9884 +4
=============================================
Files 1173 1173
Lines 85047 85049 +2
Branches 11014 11014
=============================================
+ Hits 36788 36799 +11
+ Misses 43692 43685 -7
+ Partials 4567 4565 -2 ☔ View full report in Codecov by Sentry. |
lock.lock() before try