Wanted to get the collective wisdom on the approach I'm using to identify the
thread that placed the lock. The directions state that if a thread attempts to unlock a record that it did not lock, then the unlock call should do nothing.
I've got a Vector of :
private class LockStruct {
Thread threadThatHasLock;
} // the initial reference is owned by Data and
// instantiated at Data construction
Then, in the "lock" method, keep a record of which thread placed the lock. I'm using RMI, with a server that starts up 10 servant threads to handle requests. The "lock" method is in the Data object, and is called by the public modify method in Data.
LockStruct lockRec = new LockStruct();
lockRec.threadThatHasLock = Thread.currentThread();
Then, on unlock, the following:
LockStruct Lstr = (LockStruct)lockVec.get(record);
if (Lstr.threadThatHasLock != Thread.currentThread()) {
return;
}
I believe this will work....but any thoughts would be appreciated.