Skip to content

Commit d1be99a

Browse files
committed
Make MasterCleaner private
1 parent 290b238 commit d1be99a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public class Cleaner {
5656
* 1. If a long-lived thread registers some objects in the beginning, but
5757
* then stops registering more objects, the previously registered
5858
* objects will never be cleared.
59-
* 2. When a thread exists before all its registered objects have been
60-
* cleared, the ThreadLocal instance are lost, and so are the pending
59+
* 2. When a thread exits before all its registered objects have been
60+
* cleared, the ThreadLocal instance is lost, and so are the pending
6161
* objects.
6262
*
6363
* The Master Cleaner handles the first issue by regularly handling the
@@ -66,6 +66,9 @@ public class Cleaner {
6666
* instances with the Master's reference queue.
6767
*/
6868

69+
public static final long MASTER_CLEANUP_INTERVAL_MS = 5000;
70+
public static final long MASTER_MAX_LINGER_MS = 30000;
71+
6972
private static class CleanerImpl {
7073
protected final ReferenceQueue<Object> referenceQueue = new ReferenceQueue<Object>();
7174
protected final Map<Long,CleanerRef> cleanables = new ConcurrentHashMap<Long,CleanerRef>();
@@ -118,10 +121,7 @@ protected synchronized boolean remove(long n) {
118121
}
119122
}
120123

121-
public static class MasterCleaner extends Cleaner {
122-
public static final long CLEANUP_INTERVAL_MS = 5000;
123-
public static final long MAX_LINGER_MS = 30000;
124-
124+
private static class MasterCleaner extends Cleaner {
125125
private static MasterCleaner INSTANCE;
126126

127127
public static synchronized void add(Cleaner cleaner) {
@@ -155,10 +155,10 @@ private MasterCleaner() {
155155
@Override
156156
public void run() {
157157
long now;
158-
while ((now = System.currentTimeMillis()) < lastNonEmpty + MAX_LINGER_MS || !deleteIfEmpty()) {
158+
while ((now = System.currentTimeMillis()) < lastNonEmpty + MASTER_MAX_LINGER_MS || !deleteIfEmpty()) {
159159
if (!cleanerImpls.isEmpty()) { lastNonEmpty = now; }
160160
try {
161-
Reference<?> ref = impl.referenceQueue.remove(CLEANUP_INTERVAL_MS);
161+
Reference<?> ref = impl.referenceQueue.remove(MASTER_CLEANUP_INTERVAL_MS);
162162
if(ref instanceof CleanerRef) {
163163
((CleanerRef) ref).clean();
164164
} else {

test/com/sun/jna/CallbacksTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public void callback() {
363363

364364
cb = null;
365365
System.gc();
366-
for (int i = 0; i < Cleaner.MasterCleaner.CLEANUP_INTERVAL_MS / 10 + 5 && (ref.get() != null || refs.containsValue(ref)); ++i) {
366+
for (int i = 0; i < Cleaner.MASTER_CLEANUP_INTERVAL_MS / 10 + 5 && (ref.get() != null || refs.containsValue(ref)); ++i) {
367367
Thread.sleep(10); // Give the GC a chance to run
368368
System.gc();
369369
}
@@ -372,11 +372,11 @@ public void callback() {
372372

373373
ref = null;
374374
System.gc();
375-
for (int i = 0; i < Cleaner.MasterCleaner.CLEANUP_INTERVAL_MS / 10 + 5 && (cbstruct.peer != 0 || refs.size() > 0); ++i) {
375+
for (int i = 0; i < Cleaner.MASTER_CLEANUP_INTERVAL_MS / 10 + 5 && (cbstruct.peer != 0 || refs.size() > 0); ++i) {
376376
// Flush weak hash map
377377
refs.size();
378378
try {
379-
Thread.sleep(Cleaner.MasterCleaner.CLEANUP_INTERVAL_MS + 10); // Give the GC a chance to run
379+
Thread.sleep(Cleaner.MASTER_CLEANUP_INTERVAL_MS + 10); // Give the GC a chance to run
380380
System.gc();
381381
} finally {}
382382
}

0 commit comments

Comments
 (0)