Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time Out

 
poornima sudharshan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the locking method,I use a HashMap to put the record number to be locked & the time when it would expire.
I put this as - long expireTime = System.currentTimeMillis();
the current time.
There is a timer which works every minute.
Timer lockClean = new Timer( 60000, new TimerListener() );
lockClean.start();
class TimerListener implements ActionListener {

public void actionPerformed( ActionEvent e ) {
Set recordKeys = null;
Iterator recordsIterator = null;
if(Data.lock_hash_map.isEmpty() == false) {
recordKeys = Data.lock_hash_map.keySet();
recordsIterator = recordKeys.iterator();
while( recordsIterator.hasNext() ) {
Object keyValue = recordsIterator.next();
Object timeValue = Data.lock_hash_map.get(
keyValue );
if( System.currentTimeMillis() -
Long.parseLong(
timeValue.toString()) == 300000 ) {
dbFile.unlock( Integer.parseInt(
keyValue.toString()));
System.out.println( " cleaned " );
}
}
}
}
}
In the TimerListener class, I get all the Key values from the HashMap,the key values are the record numbers.for each key I get the value - which is the timeStamp,the time when the record was put to the HashTable.What I am doing here is that I am subtracting the current time with the time stamp the record was put into the HashMap,if the difference is 5 min,the record is unlocked.
But this does not seemed to be working.
Thanks for any reply,
poornima.

 
Rick Fortier
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First let's format it so that it is easy to read.

Q:What happens if the lock has been there longer than 5 minutes?
A:Nothing. This code says it has to be expired EXACTLY 5 minutes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic