This code has a race condition and choiceCache is not volatile, so changes may
not be visible by different threads. I would recommend moving this code to a
method and making it synchronized. Do not need to make the var volatile or
worry about race conditions then.
Also I notice the config related code has a race condition and it repeatedly
reads the config even if not needed. This could be changed to only read config
when creating the cache. The words above are code below.
```java
private synchronized
LoadingCache<List<String>,WeightedRandomCollection<String>>
getCahce(VolumeChooserEnvironment env) {
if (choiceCache == null) {
ServerConfigurationFactory scf = loadConfFactory(env);
 AccumuloConfiguration systemConfiguration = scf.getSystemConfiguration();
 String propertyValue =
systemConfiguration.get(HDFS_SPACE_RECOMPUTE_INTERVAL);

long computationCacheDuration; // think this can be local var instead of
instance var
 if (StringUtils.isNotBlank(propertyValue)) {
 computationCacheDuration = Long.parseLong(propertyValue);
 } else {
computationCacheDuration = defaultComputationCacheDuration;
}
choiceCache = CacheBuilder.newBuilder()
 .expireAfterWrite(computationCacheDuration, TimeUnit.MILLISECONDS)
 .build(new
CacheLoader<List<String>,WeightedRandomCollection<String>>() {
 public WeightedRandomCollection<String> load(List<String> key) {
 return makeChoice(key, env);
 }
 });
}
return choiceCache;
}
```
[ Full content available at: https://github.com/apache/accumulo/pull/645 ]
This message was relayed via gitbox.apache.org for [email protected]