Skip to content

Repository files navigation

WeakConcurrentHashMap

A Weak Concurrent Hash Map Solution which stores the keys and values only for a specific amount of time, and then expires after that time.

 // Create a Map Object
long expiryInMillis = 1 * 60 * 1000;	// 1 minute
WeakConcurrentHashMap<String, Long> map = new WeakConcurrentHashMap<String, Long>(expiryInMillis);
// Use it
map.put("key", valueObject);
Long valueObject = map.get("key");
// quit using it
map.quitMap();

And to check if the map is alive

 if (map.isAlive()) {
// Your operations on map
}

Listener Implementation

class MyMapListener implements WeakConcurrentHashMapListener {
@Override
public void notifyOnAdd(String key, Long value) {
System.out.println("New key added to map. Key : " + key + ", Value : " + value);
}
@Override
public void notifyOnRemoval(String key, Long value) {
RestLogger.info("Key Removed from Map Key: " + key + ", Value : " + value);
}
}

@author Vivekananthan M (vivekjustthink@gmail.com)

About

Contains WeakConcurrentHashMap Java Implementation

Resources

Stars

19 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages