• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Time Out

 
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.

 
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.
 
I yam what I yam and that's all that I yam - the great philosopher Popeye. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic