Author: imario Date: Wed Jun 27 00:43:53 2007 New Revision: 551086 URL: http://svn.apache.org/viewvc?view=rev&rev=551086 Log: fixed race condition
Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java?view=diff&rev=551086&r1=551085&r2=551086 ============================================================================== --- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java (original) +++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/cache/SoftRefFilesCache.java Wed Jun 27 00:43:53 2007 @@ -36,7 +36,7 @@ * This implementation caches every file as long as it is strongly reachable by * the java vm. As soon as the vm needs memory - every softly reachable file * will be discarded. - * + * * @author <a href="mailto:[EMAIL PROTECTED]">Mario Ivankovits</a> * @version $Revision$ $Date: 2005-09-30 09:02:41 +0200 (Fr, 30 Sep * 2005) $ @@ -81,8 +81,12 @@ continue; } - FileSystemAndNameKey key = (FileSystemAndNameKey) refReverseMap - .get(ref); + FileSystemAndNameKey key; + synchronized(refReverseMap) + { + key = (FileSystemAndNameKey) refReverseMap + .get(ref); + } if (key != null) { @@ -152,7 +156,10 @@ synchronized (files) { files.put(file.getName(), ref); - refReverseMap.put(ref, key); + synchronized(refReverseMap) + { + refReverseMap.put(ref, key); + } } } @@ -190,19 +197,21 @@ synchronized (files) { - Iterator iterKeys = refReverseMap.values().iterator(); - while (iterKeys.hasNext()) + synchronized(refReverseMap) { - FileSystemAndNameKey key = (FileSystemAndNameKey) iterKeys - .next(); - if (key.getFileSystem() == filesystem) + Iterator iterKeys = refReverseMap.values().iterator(); + while (iterKeys.hasNext()) { - iterKeys.remove(); - files.remove(key.getFileName()); + FileSystemAndNameKey key = (FileSystemAndNameKey) iterKeys.next(); + if (key.getFileSystem() == filesystem) + { + iterKeys.remove(); + files.remove(key.getFileName()); + } } - } - closeFilesystem = files.size() < 1; + closeFilesystem = files.size() < 1; + } } if (closeFilesystem) @@ -240,7 +249,11 @@ { filesystemCache.clear(); } - refReverseMap.clear(); + + synchronized(refReverseMap) + { + refReverseMap.clear(); + } } public void removeFile(FileSystem filesystem, FileName name) @@ -269,7 +282,10 @@ Object ref = files.remove(key.getFileName()); if (ref != null) { - refReverseMap.remove(ref); + synchronized(refReverseMap) + { + refReverseMap.remove(ref); + } } return files.size() < 1; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]