basho/riak-java-client — pull request #160 by pcl (2012-09-01 15:50:04+00:00)
Title: Avoid string intern

Change synchronization to avoid String.intern().

Not only does String.intern() expose a surprising race condition, it is a slow call for strings not already in the pool. Which seems to be the common case, per our profiling.

This approach relies on ConcurrentHashMap.putIfAbsent(), which means that it may unnecessarily create new HashSets. However, that creation is much faster than the intern() call.

The original code also synchronizes across all other index objects that happen to have the same name in the system, which is probably not the intended behavior. I'm guessing that the intention was to establish a concurrency model that's more granular than the containing RiakIndexes object itself.

This patch strives to maintain that general concurrency model, but it's possible that simply synchronizing on 'this' would be good enough for most cases. I don't have enough insight into the decisions that led to the prior implementation, however.