If anyone is interested I found the solution, actually is very simple in this case; you only have to lock the value!
public class MapReduceDictionary extends ConcurrentHashMap<String, ArrayList<Integer>>{
private static final long serialVersionUID = 1L;
public void addValue(String key, int value) throws InterruptedException {
ArrayList<Integer> absentArr = new ArrayList<Integer>();
absentArr.add(value);
if (putIfAbsent(key, absentArr) == null) return;
synchronized (get(key)) {
get(key).add(value);
}
}
}
I debbuged this and seems to work, but if you have any comment on how this can fail, please tell me!