I want to put a value returned from a function into ConcurrentHashmap like that
private static ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<String, Object>();
public void process() {
map.put(key, function());
}
public Object function() {
return anyObject;
}
May I know the function (e.g. function()) is thread-safe or not?
Please advise if there is any tutorial
Thanks.
call itself in not thread-safe, only put operation atomic.
Instead you can use guava
Please notice makeComputingMap() call
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/MapMaker.html