Answer by Dan R. for How would we use try finally for Lock.lock and Lock.unlock
The other respondents are right: you should always use try/finally.Regarding whether (A) or (B) is correct, Sun seems to recommend (B) in the JavaDoc of ReentrantReadWriteLock (search for "finally" to...
View ArticleAnswer by Raph Levien for How would we use try finally for Lock.lock and...
It's good defensive programming. If your code ever changes so that the body throws an exception for any reason whatsoever (including, for example, OutOfMemoryError), you'll be glad you didn't leave the...
View ArticleHow would we use try finally for Lock.lock and Lock.unlock
Consider the following code. In order to prevent IndexOutOfBoundsException while calling listIterator, we use a reader lock to retrieve the index based iteartor, and writer lock else where when write...
View Article
More Pages to Explore .....