//The code that initializes the locks table
Hashtable locks = new Hashtable();
The lock method should be synchronized so that no more than one
thread can lock a record at the same time
This is the part which i could not do anything about it till this moment
Very tough
The lock hashtable will be composed of recordLock objects
inside the lock method
boolean lock succeed = false;
synchronized (locks) {
if locks.contain(recordLock) {
succeed = false;//The default case
recordLock = locks.get(recordLock);
} else { //The record has not been locked before,so lock the record
locks.add(recordLock,lockCookie);
succeed = true;
}
}
if (!(succeed)) {
recordLock.wait();
synchronized (recordLock) {
locks.add(recordLock,lockCookie);
return lockCookie;
}
else {
return lockCookie;
}
}