[
https://issues.apache.org/jira/browse/YARN-9341?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16783987#comment-16783987
]
Wilfred Spiegelenburg commented on YARN-9341:
---------------------------------------------
An {{IllegalMonitorStateException}} can only happen on unlock if the current
thread is not the owner of the lock.
I don't think we use {{tryLock}} or {{lockInterruptibly}} anywhere in our code
and thus do not need to worry about the {{IllegalMonitorStateException}}. When
you call lock the thread is blocked until the point you acquire the lock. We
should thus never proceed beyond the lock line and the finally clause should
never be executed until after the thread has lock.
The change proposed is even following the java [API
doc|https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/ReentrantLock.html]
for the locking.
+1 (non binding)
> Reentrant lock() before try
> ---------------------------
>
> Key: YARN-9341
> URL: https://issues.apache.org/jira/browse/YARN-9341
> Project: Hadoop YARN
> Issue Type: Bug
> Components: yarn
> Affects Versions: 3.1.0
> Reporter: Prabhu Joseph
> Assignee: Prabhu Joseph
> Priority: Minor
> Attachments: YARN-9341-001.patch
>
>
> As a best practice - Reentrant lock has to be acquired before try clause.
> https://stackoverflow.com/questions/31058681/java-locking-structure-best-pattern
> There are many places where lock is obtained inside try.
> {code}
> try {
> this.writeLock.lock();
> ....
> } finally {
> this.writeLock.unlock();
> }
> {code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]