Rework SoftRefFilesCache locking part 1 (#158)
* SoftRefFilesCache: don't call super.close()
AbstractVfsComponent.close() is documented to do nothing, so there's
no point in calling it.
* SoftRefFilesCache: use isEmpty() instead of "size()<1"
For some containers, size() is O(n), but isEmpty() is always O(1).
* SoftRefFilesCache: remove redundant isInterrupted() check
The following ReferenceQueue.remove() call will do that check again.
* SoftRefFilesCache: simplify the InterruptedException catch block
By reversing the order of "while" and "try/catch", we can simply omit
the "break" pseudo-goto statement.
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/SoftRefFilesCache.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/SoftRefFilesCache.java
index 8243380..1e597d8 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/SoftRefFilesCache.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/cache/SoftRefFilesCache.java
@@ -69,8 +69,8 @@
@Override
public void run() {
- loop: while (!requestEnd && !Thread.currentThread().isInterrupted()) {
- try {
+ try {
+ while (!requestEnd) {
final Reference<?> ref = refQueue.remove(TIMEOUT);
if (ref == null) {
continue;
@@ -86,12 +86,11 @@
} finally {
lock.unlock();
}
- } catch (final InterruptedException e) {
- if (!requestEnd) {
- VfsLog.warn(getLogger(), log,
+ }
+ } catch (final InterruptedException e) {
+ if (!requestEnd) {
+ VfsLog.warn(getLogger(), log,
Messages.getString("vfs.impl/SoftRefReleaseThread-interrupt.info"));
- }
- break loop;
}
}
}
@@ -242,7 +241,7 @@
}
fileSystemCache.remove(fileSystem);
- if (fileSystemCache.size() < 1) {
+ if (fileSystemCache.isEmpty()) {
endThread();
}
/*
@@ -253,8 +252,6 @@
@Override
public void close() {
- super.close();
-
endThread();
lock.lock();
@@ -295,7 +292,7 @@
}
protected Map<FileName, Reference<FileObject>> getOrCreateFilesystemCache(final FileSystem fileSystem) {
- if (fileSystemCache.size() < 1) {
+ if (fileSystemCache.isEmpty()) {
startThread();
}