You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/02/28 13:59:12 UTC
[commons-vfs] branch master updated: Rework SoftRefFilesCache
locking part 1 (#158)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push:
new 4e37bb6 Rework SoftRefFilesCache locking part 1 (#158)
4e37bb6 is described below
commit 4e37bb698b6c8d18e4e102a6ed6e6b35925ee35f
Author: Max Kellermann <mk...@cm4all.com>
AuthorDate: Sun Feb 28 14:58:57 2021 +0100
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.
---
.../apache/commons/vfs2/cache/SoftRefFilesCache.java | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
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 @@ public class SoftRefFilesCache extends AbstractFilesCache {
@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 @@ public class SoftRefFilesCache extends AbstractFilesCache {
} 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 @@ public class SoftRefFilesCache extends AbstractFilesCache {
}
fileSystemCache.remove(fileSystem);
- if (fileSystemCache.size() < 1) {
+ if (fileSystemCache.isEmpty()) {
endThread();
}
/*
@@ -253,8 +252,6 @@ public class SoftRefFilesCache extends AbstractFilesCache {
@Override
public void close() {
- super.close();
-
endThread();
lock.lock();
@@ -295,7 +292,7 @@ public class SoftRefFilesCache extends AbstractFilesCache {
}
protected Map<FileName, Reference<FileObject>> getOrCreateFilesystemCache(final FileSystem fileSystem) {
- if (fileSystemCache.size() < 1) {
+ if (fileSystemCache.isEmpty()) {
startThread();
}