Skip to content

Commit 6080be7

Browse files
committed
Ensure that masterCleanup runs at least every 2*MASTER_CLEANUP_INTERVAL
1 parent ab7d880 commit 6080be7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/com/sun/jna/internal/Cleaner.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,18 @@ private MasterCleaner() {
155155
@Override
156156
public void run() {
157157
long now;
158+
long lastMasterRun = 0;
158159
while ((now = System.currentTimeMillis()) < lastNonEmpty + MASTER_MAX_LINGER_MS || !deleteIfEmpty()) {
159160
if (!cleanerImpls.isEmpty()) { lastNonEmpty = now; }
160161
try {
161162
Reference<?> ref = impl.referenceQueue.remove(MASTER_CLEANUP_INTERVAL_MS);
162163
if(ref instanceof CleanerRef) {
163164
((CleanerRef) ref).clean();
164-
} else {
165+
}
166+
// "now" is not really *now* at this point, but off by no more than MASTER_CLEANUP_INTERVAL_MS
167+
if (lastMasterRun + MASTER_CLEANUP_INTERVAL_MS <= now) {
165168
masterCleanup();
169+
lastMasterRun = now;
166170
}
167171
} catch (InterruptedException ex) {
168172
// Can be raised on shutdown. If anyone else messes with

0 commit comments

Comments
 (0)