This week's book giveaway is in the OCAJP forum. We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line! See this thread for details.
I have a general question regarding the correct usage of a ReadWriteLock in Java 5.
Andrew's book states that if you use a lock, it's best to unlock in a finally clause, like here:
But what is the best way to unlock if you downgrade from a writeLock to a readLock?
Now I have
The readLocked and writeLocked boolean's are required to guarantee unlocking in case of an error but to prevent IllegalMonitorState exceptions to occur if no errors occur. But I don't really feel comfortable with this solution. Does anyone have a suggestion on how to improve this?
Thanks a lot.
posted 10 years ago
Solved. With a little bit of refactoring I was able to restructure my code. Now I have the following
Quite simple actually. Don't know why I didn't see this last night.