|
|
|
Back to newsletter 278 contents
In last month's newsletter I explained how eventual consistency and strict consistency differ. The concept usually applies to data store consistency, but one of my readers asked whether there were examples where these apply in common Java code. Any synchronized method provides strict consistency. The Hashtable class is a good example of a strictly consistent class.
For a good common example of eventual consistency, an example is the related hash map ConcurrentHashMap. It has aggregate status methods, eg size(), isEmpty(), containsValue(), which are all eventually consistent. That is, a concurrent update may have completed in another thread but these methods would not necessarily return the global state at that time. Hashtable.size() always returns the size corresponding to the last update from any thread that completed on the map (strictly consistent); ConcurrentHashMap.size() is usually accurate except when a concurrent update has recently completed on another thread (eventually consistent).
(For precisionists, ConcurrentHashmap.size() is actually an estimate rather than eventually consistent because the value returned is not necessarily one that was ever correct, whereas an eventually consistent value would have definitely been correct at some point. But I think it's a good enough example). Now on to all the usual newsletter list of links, tips, tools, news and articles, and as usual I've extracted all the tips into this month's tips page
Java performance tuning related news
Java performance tuning related tools
Back to newsletter 278 contents