8003335: Better handling of Finalizer thread
Reviewed-by: alanb, ahgross
This commit is contained in:
parent
1bb9122f69
commit
3b34f3b493
@ -38,9 +38,9 @@ final class Finalizer extends FinalReference { /* Package-private; must be in
|
||||
*/
|
||||
static native void invokeFinalizeMethod(Object o) throws Throwable;
|
||||
|
||||
static private ReferenceQueue queue = new ReferenceQueue();
|
||||
static private Finalizer unfinalized = null;
|
||||
static private Object lock = new Object();
|
||||
private static ReferenceQueue queue = new ReferenceQueue();
|
||||
private static Finalizer unfinalized = null;
|
||||
private static final Object lock = new Object();
|
||||
|
||||
private Finalizer
|
||||
next = null,
|
||||
@ -142,7 +142,11 @@ final class Finalizer extends FinalReference { /* Package-private; must be in
|
||||
/* Called by Runtime.runFinalization() */
|
||||
static void runFinalization() {
|
||||
forkSecondaryFinalizer(new Runnable() {
|
||||
private volatile boolean running;
|
||||
public void run() {
|
||||
if (running)
|
||||
return;
|
||||
running = true;
|
||||
for (;;) {
|
||||
Finalizer f = (Finalizer)queue.poll();
|
||||
if (f == null) break;
|
||||
@ -155,7 +159,11 @@ final class Finalizer extends FinalReference { /* Package-private; must be in
|
||||
/* Invoked by java.lang.Shutdown */
|
||||
static void runAllFinalizers() {
|
||||
forkSecondaryFinalizer(new Runnable() {
|
||||
private volatile boolean running;
|
||||
public void run() {
|
||||
if (running)
|
||||
return;
|
||||
running = true;
|
||||
for (;;) {
|
||||
Finalizer f;
|
||||
synchronized (lock) {
|
||||
@ -168,10 +176,14 @@ final class Finalizer extends FinalReference { /* Package-private; must be in
|
||||
}
|
||||
|
||||
private static class FinalizerThread extends Thread {
|
||||
private volatile boolean running;
|
||||
FinalizerThread(ThreadGroup g) {
|
||||
super(g, "Finalizer");
|
||||
}
|
||||
public void run() {
|
||||
if (running)
|
||||
return;
|
||||
running = true;
|
||||
for (;;) {
|
||||
try {
|
||||
Finalizer f = (Finalizer)queue.remove();
|
||||
|
Loading…
x
Reference in New Issue
Block a user