private static HashMap<String, FileInfo> sFileInfoObjectList = new CacheLinkedHashMap<String, FileInfo>();
public static synchronized FileInfo getFileInfoForProvider(...) {
FileInfo foundFileInfo = null;
(...)
foundFileInfo = sFileInfoObjectList.get(hashEntryKey);
(...)
sFileInfoObjectList.put(hashEntryKey, foundFileInfo);
(...)
}
public static synchronized void removeFileInfoForProvider(final int providerId) {
Thread thread = new Thread() {
@Override
public void run() {
Iterator<Entry<String, FileInfo>> it = sFileInfoObjectList.entrySet().iterator();
while (it.hasNext()) {
Entry<String, FileInfo> pair = it.next();
FileInfo info = pair.getValue();
if (providerId == info.mProvider) {
it.remove();
}
}
}
};
}
run() メソッドで ConccurentModificationException を取得しています。私は次のことを試しましたが、うまくいきませんでした:
public void run() {
synchronized(sFileInfoObjectList) {
Iterator<Entry<String, FileInfo>> it = sFileInfoObjectList.entrySet().iterator();
while (it.hasNext()) {
Entry<String, FileInfo> pair = it.next();
FileInfo info = pair.getValue();
if (providerId == info.mProvider) {
it.remove();
}
}
}
}