I'm developing for Android 2.2, and a bit confused as to how ReentrantLocks work. Can the following code ever throw an IllegalMonitorStateException? I ask because I don't see how it can--according to the API, tryLock returns true if and only if the lock is successfully obtained--but occasionally the unlock() command does.
public void lockDemo() {
ReentrantLock myLock = new ReentrantLock();
if (myLock.tryLock()) {
System.out.println("Lock obtained");
myLock.unlock();
}
}