Skip to content

Commit

Permalink
Ensure that masterCleanup runs at least every 2*MASTER_CLEANUP_INTERVAL
Browse files Browse the repository at this point in the history
  • Loading branch information
pmconrad committed Aug 15, 2023
1 parent ab7d880 commit 6080be7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/com/sun/jna/internal/Cleaner.java
Expand Up @@ -155,14 +155,18 @@ private MasterCleaner() {
@Override
public void run() {
long now;
long lastMasterRun = 0;
while ((now = System.currentTimeMillis()) < lastNonEmpty + MASTER_MAX_LINGER_MS || !deleteIfEmpty()) {
if (!cleanerImpls.isEmpty()) { lastNonEmpty = now; }
try {
Reference<?> ref = impl.referenceQueue.remove(MASTER_CLEANUP_INTERVAL_MS);
if(ref instanceof CleanerRef) {
((CleanerRef) ref).clean();
} else {
}
// "now" is not really *now* at this point, but off by no more than MASTER_CLEANUP_INTERVAL_MS
if (lastMasterRun + MASTER_CLEANUP_INTERVAL_MS <= now) {
masterCleanup();
lastMasterRun = now;
}
} catch (InterruptedException ex) {
// Can be raised on shutdown. If anyone else messes with
Expand Down

0 comments on commit 6080be7

Please sign in to comment.