-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.4
-
sparc
-
solaris_2.5.1
Name: rm29839 Date: 10/28/97
I have managed to get an application I am working on to deadlock. Nothing strange about that, I know.
But this deadlock is caused by the random nature of finalizer activation. I have written a small "application"
( 100 lines ) that reproduces the problem. I will provide a quick overview of the problem, including an edited
thread dump. A URL to the code is provided. Can anybody tell me if I am doing something wrong, or if I am
being hit by a JDK bug.
Regards,
Mike Hogan
---------------------------------------------------------------------------------
The code is available at the following URL:
http://www-irl.iona.com/hyplan/mhogan/deadlock/
Problem overview:
I am using JDK1.1.4. I have a class that inherits from PrintStream and overrides println to append to a text area.
This allows me to redirect stdout and stderr to a textarea, providing a console facility. There is a class inheriting from
Thread that simply creates instances of TestObject. It maintains no references to the created instances, so the i
nstances are finalized. The finalize method on these instances prints text to stdout and stderr. The main routine
of the application redirects stdout and stderr to a textarea using the first class, and then begins spawning threads
that create ( and finalize ) TestObject instances. This results in the stdout and stderr from the finalize methods
being redirected to the textarea.
However, this will result in a deadlock when the finalizer thread trys to attain a lock on the textarea while
writing to the redirected stdout, and the thread currently holding the lock on the textarea is waiting on the
"Finalize me queue lock".
Thread dump during deadlock.
This is an edited thread dump from the deadlocked process. You will notice that Thread 10 has a lock on the
textarea and is waiting on the "Finalize me queue lock". While the Finalizer thread is waiting on the textarea.
"Thread-10" (TID:0xee707a10, sys_thread_t:0xede31de0, state:CW) prio=6
java.lang.String.<init>(String.java)
java.awt.TextComponent.getText(TextComponent.java:112)
java.awt.TextArea.appendText(TextArea.java:180)
java.awt.TextArea.append(TextArea.java:171)
DeadlockTest.TextAreaPrintStream.println(TextAreaPrintStream.java:18)
DeadlockTest.TestObject.<init>(TestObject.java:7)
DeadlockTest.ObjectGenerationThread.run(ObjectGenerationThread.java:9)
"Finalizer thread" (TID:0xee700220, sys_thread_t:0xee2c1de0, state:MW) prio=1
java.awt.TextArea.append(TextArea.java:170)
DeadlockTest.TextAreaPrintStream.println(TextAreaPrintStream.java:18)
DeadlockTest.TestObject.finalize(TestObject.java:13)
"Async Garbage Collector" (TID:0xee7001d8, sys_thread_t:0xee2f1de0, state:CW) prio=1
"Idle thread" (TID:0xee700190, sys_thread_t:0xee3c1de0, state:R) prio=0 *current thread*
"Clock" (TID:0xee7000d0, sys_thread_t:0xee3f1de0, state:CW) prio=12
"main" (TID:0xee7000a8, sys_thread_t:0x41018, state:MW) prio=5
java.awt.TextArea.append(TextArea.java:170)
DeadlockTest.TextAreaPrintStream.println(TextAreaPrintStream.java:18)
DeadlockTest.DeadlockTester.main(DeadlockTester.java:24)
Monitor Cache Dump:
<unknown key> (0xee2f1de0): <unowned>
Waiting to be notified:
"Async Garbage Collector"
java.awt.TextArea@EE703CC8/EE740B98: owner "Thread-10" (0xede31de0, 2 entries)
Waiting to enter:
"Thread-15"
"Thread-13"
"Thread-17"
"Thread-16"
"Thread-6"
"Thread-8"
"Thread-4"
"Thread-11"
"Thread-9"
"Thread-14"
"Thread-7"
"Thread-12"
"Thread-5"
"main"
"Thread-18"
"Finalizer thread"
sun.awt.motif.MToolkit@EE704A08/EE7430F8: owner "Thread-10" (0xede31de0, 1 entry)
Waiting to enter:
"Screen Updater"
"AWT-Input"
"AWT-Motif"
"AWT-EventQueue-0"
Registered Monitor Dump:
Thread queue lock: <unowned>
Name and type hash table lock: <unowned>
String intern lock: <unowned>
JNI pinning lock: <unowned>
JNI global reference lock: <unowned>
BinClass lock: <unowned>
Class loading lock: <unowned>
Java stack lock: <unowned>
Code rewrite lock: <unowned>
Heap lock: <unowned>
Has finalization queue lock: <unowned>
Finalize me queue lock: <unowned>
Waiting to be notified:
"Thread-10"
Monitor IO lock: <unowned>
Child death monitor: <unowned>
Event monitor: <unowned>
I/O monitor: <unowned>
Alarm monitor: <unowned>
Waiting to be notified:
"Clock"
Sbrk lock: <unowned>
Monitor cache expansion lock: <unowned>
Monitor registry: owner "Idle thread" (0xee3c1de0, 1 entry)
Thread Alarm Q:
sys_thread_t 0xee2f1de0 [Timeout in 728 ms]
======================================================================
ronan.mandel@Eng 1997-10-28
I don't get it to deadlock, I just get a hang.
- duplicates
-
JDK-4091873 (refs) Calling a synchronized method from finalize() can lock VM
-
- Closed
-