以下代码,多线程运行:
private static final Map<String, keyinfo> mapKeys = new ConcurrentHashMap<String, keyinfo>();
private static void purgeOldKeys() {
for (Map.Entry<String, keyinfo> key : mapKeys.entrySet()) {
if(key.getValue().createTime + keyCacheTime < getCurrentDBTime())
mapKeys.remove(key);
}
}
我可以避免同步器吗?
还是因为删除已经删除的元素,没有根据 JavaDoc 定义,仍然需要同步器?