JDK-4152761 : java does not exit main when Panel is created
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 1998-06-26
  • Updated: 2000-07-19
  • Resolved: 2000-07-19
Related Reports
Duplicate :  
Relates :  
Description
The following simple class is a subclass of Panel.  In the main
program, I create the panel and exit from main.  When I run
this program, it hangs at the end and never exits.


package echeck.ofx;

import java.io.*;
import java.util.*;
import java.awt.event.*;
import java.awt.*;

public class OFXTester  extends Panel
{
    /**
     * Constructor initializes this object.
     */
    public OFXTester()
    {
    }


     public static void main(String [] args)
     {
        int active = Thread.activeCount();
        System.err.println("active = " + active);

        Thread[] threads = new Thread[active];
        Thread.enumerate(threads);
        System.err.println("before construction");
        for (int j=0; j<threads.length; j++) {
           System.err.println(threads[j].toString());
        }

        System.err.println("doing nothing!!");
        OFXTester test = new OFXTester();

        active = Thread.activeCount();
        System.err.println("active = " + active);

        threads = new Thread[active];
        System.err.println("after contruction");
        Thread.enumerate(threads);
        for (int i=0; i<threads.length; i++) {
           System.err.println(threads[i].toString());
        }

        System.err.println("done!!");
     }
}



The standard error for this program is given below.  It includes a full dump of all the threads which is created when I hit "Ctrl-\" when the program is hanging.

active = 1
before construction
Thread[main,5,main]
doing nothing!!
active = 4
after contruction
Thread[main,5,main]
Thread[AWT-EventQueue-0,5,main]
Thread[AWT-Input,5,main]
Thread[AWT-Motif,5,main]
done!!
SIGQUIT   3*   quit

Full thread dump:
    "AWT-Motif" (TID:0xee308748, sys_thread_t:0x1d6b00, state:CW) prio=5
        at java.lang.Object.wait(Native Method)
        at sun.awt.motif.MToolkit.run(Native Method)
        at java.lang.Thread.run(Thread.java:490)
    "AWT-Input" (TID:0xee308770, sys_thread_t:0x1cdde0, state:CW) prio=5
        at sun.awt.motif.InputThread.run(Native Method)
    "AWT-EventQueue-0" (TID:0xee308578, sys_thread_t:0x1b4c70, state:CW) prio=5
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:315)
        at java.awt.EventQueue.getNextEvent(EventQueue.java:122)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:44)
    "SoftReference sweeper" (TID:0xee3046c8, sys_thread_t:0x89528, state:CW) prio=9
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:315)
        at java.lang.Runtime.waitForMemoryAdvice(Runtime.java:569)
        at java.lang.ref.SoftReference$Sweeper.run(SoftReference.java:524)
        at java.lang.Thread.run(Thread.java:490)
    "Finalizer" (TID:0xee300318, sys_thread_t:0x682a0, state:CW) prio=8
        at java.lang.Object.wait(Native Method)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:107)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:122)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:127)
    "Reference handler" (TID:0xee3003c8, sys_thread_t:0x584b8, state:CW) prio=10
        at java.lang.Object.wait(Native Method)
        at java.lang.Object.wait(Object.java:315)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:186)
    "Async Garbage Collector" (TID:0xee3001b0, sys_thread_t:0x61160, state:CW) prio=1
    "Idle thread" (TID:0xee3001f8, sys_thread_t:0x58910, state:R) prio=0 *current thr
ead*
    "Clock" (TID:0xee3002d0, sys_thread_t:0x587e8, state:CW) prio=12
    "main" (TID:0xee300038, stillborn) : <thread not active>
Monitor Cache Dump:
Registered Monitor Dump:
    utf8 hash table: <unowned>
    JNI pinning lock: <unowned>
    JNI global reference lock: <unowned>
    BinClass lock: <unowned>
    Class linking lock: <unowned>
    System class loader lock: <unowned>
    Code rewrite lock: <unowned>
    Heap lock: <unowned>
    Monitor IO lock: <unowned>
    Child death monitor: <unowned>
    Event monitor: <unowned>
    I/O monitor: <unowned>
        Waiting to be notified:
            "AWT-Input" (0x1cdde0)
    Alarm monitor: <unowned>
        Waiting to be notified:
            "Clock" (0x587e8)
    Sbrk lock: <unowned>
    Thread queue lock: <unowned>
        Waiting to be notified:
            "main" (0x0)
    Monitor registry: owner "Idle thread" (0x58910, 1 entry)
Thread Alarm Q:
    sys_thread_t 0x1cdde0   [Timeout in 104 ms]
    sys_thread_t 0x61160   [Timeout in 235 ms]


Comments
WORK AROUND Call System.exit(0); as the last line of main.
11-06-2004

EVALUATION There are several new cases in 1.2 where the Toolkit is initialized. Once this happens, a program will not exit when main returns. Apparently, instantiating a Panel is one of these new cases. This bug is related to BugId 4125114. david.mendenhall@eng 1998-06-27
27-06-1998