TimedOutHashTable

public class TimedOutHashTable extends Hashtable

The TimedOutDHashTable is the hashtable that provides time out features. All timed-out key and value will be cleared in the hashtable. The default interval for sweeping away all timed out record is 5 second. For the release of JDK5.0 , this class can inherit java.util.conncurrent.ConcurrentHashMap for better performance. Creation Date: 25/6/2007 17/7/2007 1. Bug Fixed that return false for invoking containsValue(Object) because of invalid implementation of TimedOutEntry.equals(Object). 2. Bug Fixed that the memory leak issue when de-referecing timed-out hashtable due to there is one reference in the internal TimedOutTask. Now you are required to call complete() when you want to gc the hashtable.

Author:Twinsen Tsang

Constructors

TimedOutHashTable

public TimedOutHashTable()

Constructor.

TimedOutHashTable

public TimedOutHashTable(long sweepInterval)

Explicit Constructor.

Parameters:
  • sweepInterval – The sweepInterval for sweeping away the timed-out hash-record.

Methods

complete

public void complete()

Invoke this method when you no longer want to use the hashtable anymore. (it will be gc soon).

contains

public boolean contains(Object value)

containsValue

public boolean containsValue(Object value)

get

public Object get(Object key)

getSweepInterval

public long getSweepInterval()
Returns:the sweeping interval for the hash table.

put

public Object put(Object key, Object value)

put

public Object put(Object key, Object value, long timeOutInMs)

Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null. The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
  • key – the hashtable key.
  • value – the value
  • timeOutInMS – how long does this record time out.
Returns:

the previous value of the specified key in this hashtable, or null if it did not have one.

put

public Object put(Object key, Object value, Date timeOutDate)

Maps the specified key to the specified value in this hashtable. Neither the key nor the value can be null. The value can be retrieved by calling the get method with a key that is equal to the original key.

Parameters:
  • key – the hashtable key.
  • value – the value
  • timeOutDate – how long does this record time out in date object.
Returns:

the previous value of the specified key in this hashtable, or null if it did not have one.

setListener

public void setListener(TimedOutEntryListener listener)
Parameters:
  • listener – The listener for receiving removal event of timed-out entry.

See also: hk.hku.cecid.piazza.commons.util.TimedOutEntryListener.