Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

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.
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic