This week's book giveaway is in the Agile and Other Processes forum.We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!See this thread for details.

How to remove unlocked records

Anurag Mishra

Ranch Hand

Posts: 133

posted 14 years ago

When clients locks a particular record say, Client A locks record 12 but but he dont want to book the seat on that record and he left that record as it is(means locked) how that record will be unlocked, so that another client can access that record. My record locking method is: public void lock(int record) throws IOException { System.out.println("Record "+record+" locked"); if(record==-1){ System.out.println("Database locked"); } synchronized(lockVector) { while(lockVector.contains(new Integer(record))| |(lockVector.contains(new Integer(-1)))){ try{ lockVector.wait(); }catch(InterruptedException e){ throw new IOException("lock failed"); } } lockVector.add(new Integer(record)); } }

People on this board have suggested many ways to remove locks. You can look into the Unreferenced interface, use the finalize method, let locks time out, give locks heart beats, design a delogger like a defragger, etc. All these schemes might actually accomplish the same goal, but the assignment never asks for any of this. In fact, if locks were left in the DB as the result of the client going down at the wrong moment in time, then the DB is probably corrupt anyway. - Mike

Trevor Dunn

Ranch Hand

Posts: 84

posted 14 years ago

Mike is right. I never implemented any sort of removal for stale locks and it did not affect me. You might want to mention it in your design document that it would be a good idea to implement it but the since the spec does not call for it you did not do it. Also all these procedure for getting rid of stale locks are fine but I found the key to this assignment is keep it simple. Trevor

Anurag Mishra

Ranch Hand

Posts: 133

posted 14 years ago

Thanks Mike and Tev. I also think that there is no need for the removal of stale locks.I should keep my assignment as simple as possible. Anurag

Anurag Mishra

Ranch Hand

Posts: 133

posted 14 years ago

Thanks Mike and Tev. I also think that there is no need for the removal of stale locks.I should keep my assignment as simple as possible. Anurag