我的代码:
class Pair {
public String key;
public String value;
}
Iterator<Pair> pairs;
HashMap<String, String> map = new HashMap<String, String>();
while (pairs.hasNext()) {
Pair p = pairs.next();
map.put(p.ket, p.value)
// then put p.key to another thread for RPC
// after returned, lookup the hashmap, join the result and p.value, and output
}
每次 RPC 完成后,线程池都会查找 hashmap,将 RPC 结果和键值连接起来。这是原子的吗?