123
124 /* High-priority thread to enqueue pending References
125 */
126 private static class ReferenceHandler extends Thread {
127
128 ReferenceHandler(ThreadGroup g, String name) {
129 super(g, name);
130 }
131
132 public void run() {
133 for (;;) {
134 Reference r;
135 synchronized (lock) {
136 if (pending != null) {
137 r = pending;
138 pending = r.discovered;
139 r.discovered = null;
140 } else {
141 try {
142 lock.wait();
143 } catch (InterruptedException x) { }
144 continue;
145 }
146 }
147
148 // Fast path for cleaners
149 if (r instanceof Cleaner) {
150 ((Cleaner)r).clean();
151 continue;
152 }
153
154 ReferenceQueue q = r.queue;
155 if (q != ReferenceQueue.NULL) q.enqueue(r);
156 }
157 }
158 }
159
160 static {
161 ThreadGroup tg = Thread.currentThread().getThreadGroup();
162 for (ThreadGroup tgn = tg;
163 tgn != null;
|
123
124 /* High-priority thread to enqueue pending References
125 */
126 private static class ReferenceHandler extends Thread {
127
128 ReferenceHandler(ThreadGroup g, String name) {
129 super(g, name);
130 }
131
132 public void run() {
133 for (;;) {
134 Reference r;
135 synchronized (lock) {
136 if (pending != null) {
137 r = pending;
138 pending = r.discovered;
139 r.discovered = null;
140 } else {
141 try {
142 lock.wait();
143 } catch (InterruptedException | OutOfMemoryError x) { }
144 continue;
145 }
146 }
147
148 // Fast path for cleaners
149 if (r instanceof Cleaner) {
150 ((Cleaner)r).clean();
151 continue;
152 }
153
154 ReferenceQueue q = r.queue;
155 if (q != ReferenceQueue.NULL) q.enqueue(r);
156 }
157 }
158 }
159
160 static {
161 ThreadGroup tg = Thread.currentThread().getThreadGroup();
162 for (ThreadGroup tgn = tg;
163 tgn != null;
|