public static void main(String args[]) throws InterruptedException {
Date start = new Date();
System.out.println("Start: " + start);
DB db = DBMaker.memoryDB().transactionDisable().cacheHashTableEnable()
.cacheSize(20).closeOnJvmShutdown().make();
// Create a Hash Map in DB.
HTreeMap<String, Object> map = db.hashMapCreate("test").counterEnable()
.expireAfterAccess(2, TimeUnit.SECONDS)
.expireAfterWrite(2, TimeUnit.SECONDS)
.keySerializer(Serializer.STRING).makeOrGet();
map.put("key", "value");
db.commit(); // persist changes into disk
System.out.println(map.get("key"));
Thread.sleep(5000);
System.out.println(map.get("key"));
db.close();
Date end = new Date();
System.out.println("End: " + end);
System.out.println("Total Time in s: "
+ (end.getTime() - start.getTime()) / 1000);
}Output
Start: Sun Oct 04 21:57:46 EDT 2015
value
value
End: Sun Oct 04 21:57:51 EDT 2015
Total Time in s: 5
WARNING: HTreeMap Expiration should not be used with transaction enabled. It can lead to data corruption, commit might happen while background thread works, and only part of expiration data will be commited.
Expiration times are approximate. It would be too big overhead to do exact calculation, so MapDB expires entries as best effort. Actual numbers could be a few hundreds different.
Jan
--
You received this message because you are subscribed to the Google Groups "MapDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapdb+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.