提交 246c9a48 编写于 作者: C chegar

8003335: Better handling of Finalizer thread

Reviewed-by: alanb, ahgross
上级 473837e6
...@@ -38,9 +38,9 @@ final class Finalizer extends FinalReference { /* Package-private; must be in ...@@ -38,9 +38,9 @@ final class Finalizer extends FinalReference { /* Package-private; must be in
*/ */
static native void invokeFinalizeMethod(Object o) throws Throwable; static native void invokeFinalizeMethod(Object o) throws Throwable;
static private ReferenceQueue queue = new ReferenceQueue(); private static ReferenceQueue queue = new ReferenceQueue();
static private Finalizer unfinalized = null; private static Finalizer unfinalized = null;
static private Object lock = new Object(); private static final Object lock = new Object();
private Finalizer private Finalizer
next = null, next = null,
...@@ -142,7 +142,11 @@ final class Finalizer extends FinalReference { /* Package-private; must be in ...@@ -142,7 +142,11 @@ final class Finalizer extends FinalReference { /* Package-private; must be in
/* Called by Runtime.runFinalization() */ /* Called by Runtime.runFinalization() */
static void runFinalization() { static void runFinalization() {
forkSecondaryFinalizer(new Runnable() { forkSecondaryFinalizer(new Runnable() {
private volatile boolean running;
public void run() { public void run() {
if (running)
return;
running = true;
for (;;) { for (;;) {
Finalizer f = (Finalizer)queue.poll(); Finalizer f = (Finalizer)queue.poll();
if (f == null) break; if (f == null) break;
...@@ -155,7 +159,11 @@ final class Finalizer extends FinalReference { /* Package-private; must be in ...@@ -155,7 +159,11 @@ final class Finalizer extends FinalReference { /* Package-private; must be in
/* Invoked by java.lang.Shutdown */ /* Invoked by java.lang.Shutdown */
static void runAllFinalizers() { static void runAllFinalizers() {
forkSecondaryFinalizer(new Runnable() { forkSecondaryFinalizer(new Runnable() {
private volatile boolean running;
public void run() { public void run() {
if (running)
return;
running = true;
for (;;) { for (;;) {
Finalizer f; Finalizer f;
synchronized (lock) { synchronized (lock) {
...@@ -168,10 +176,14 @@ final class Finalizer extends FinalReference { /* Package-private; must be in ...@@ -168,10 +176,14 @@ final class Finalizer extends FinalReference { /* Package-private; must be in
} }
private static class FinalizerThread extends Thread { private static class FinalizerThread extends Thread {
private volatile boolean running;
FinalizerThread(ThreadGroup g) { FinalizerThread(ThreadGroup g) {
super(g, "Finalizer"); super(g, "Finalizer");
} }
public void run() { public void run() {
if (running)
return;
running = true;
for (;;) { for (;;) {
try { try {
Finalizer f = (Finalizer)queue.remove(); Finalizer f = (Finalizer)queue.remove();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册