Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4051303

AWT object being painted and disposed in race condition causing hang/assert fail



    • b01
    • x86
    • windows_nt
    • Not verified


      (GuiHang - see below) application can be made to hang or throw assertion failures (in java_g) quite easily.

      The problem is that the java code is (indirectly) disposing some objects
      while they're being painted. The AWT code for NT appears to have been
      written very carefully to
        a) make sure messages are handled before the Windows object is
           destroyed, and
        b) make sure that if the Java and C++ objects have been destroyed,
           the message is handled safely.

      The problem is that there is no lock to prevent painting (or any other
      message handling) from occurring at the same time, on the same object,
      that is being disposed.
      The 60 line program below causes the user interface to freeze if you hit
      the "Hurt Me" button enough times (somewhere between 2 and 20 for us on our
      NT machines).
      Some relevant facts are:
      1. Windows NT, JDK 1.1.1 and JRE 1.1.1 fail; AIX 1.1 does not fail
      2. Press the "Hurt Me" button faster than the screen can repaint
      3. When the failure occurs, the jdb info is shown below. Note that threads
      5 and 6 are "running", and thread 5 is in
      sun.awt.windows.WComponentPeer.dispose (WComponentPeer:121). It never
      comes back.
      4. When I try to kill the java process running GuiHang, it dumps the stuff
      in the last snippet below. If I understand it correctly, the
      "AWT-EventQueue-0" thread and the "Debugger Agent" are the only threads
      holding monitors, so it
      doesn't look like a deadly embrace of monitors.
      5. Our product has seen other failure symptoms including the one shown by
      They all seem to relate to the AWT. See the last section of this note for
      some more info.
      ------ the test program
      import java.awt.*;
      import java.awt.event.*;
      public class GuiHang {
        public Frame frame;
        public BigPanel bp;
        public static final int Rows = 50;
        private void init() {
          frame = new Frame("GUI Hang");
          frame.setLayout(new BorderLayout());
          Button button = new Button("Hurt Me");
          button.addActionListener(new NavigateListener());
          frame.add("West", button);
          bp = new BigPanel(Rows);
          frame.add("Center", bp);
          frame.setBounds(50, 50, 400, 600);
        public void navigate() {
          bp = new BigPanel(Rows);
          frame.add("Center", bp);
        public class NavigateListener implements ActionListener {
          public void actionPerformed(ActionEvent e) {
        public static void main(String argv[]) {
          GuiHang gh;
          gh = new GuiHang();
      class BigPanel extends Panel {
        public BigPanel(int numRows) {
          setLayout(new GridLayout(numRows, 2));
          for(int i = 0; i < numRows; i++) {
            add(new Label("Row "+(i+1)));
            TextField field = new TextField();




            jlockesunw Jonathan Locke (Inactive)
            rschiavisunw Richard Schiavi (Inactive)
            0 Vote for this issue
            0 Start watching this issue