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

Javadoc for method EventQueue.pop should prevent dead lock situation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 1.4.0
    • docs
    • beta2
    • sparc
    • solaris_2.6



      Name: dsR10051 Date: 04/23/2001


      The current implementation of method
      protected void java.awt.EventQueue.pop()
      locks the previous queue in the "stack"
      before the current:
      --- * @(#)EventQueue.java 1.76 01/02/26 ---

          /**
           * Stop dispatching events using this <code>EventQueue</code> instance.
           * Any pending events are transferred to the previous
           * <code>EventQueue</code> for processing by it.
           *
           * @exception EmptyStackException if no previous push was made
           * on this <code>EventQueue</code>
           * @see java.awt.EventQueue#push
           */
          protected void pop() throws EmptyStackException {
      ...
              EventQueue prev = previousQueue;
              synchronized ((prev != null) ? prev : this) {
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                synchronized(this) {
                ^^^^^^^^^^^^^^^^^^
      ...
      ---

      This order may be broken
      if subclass declares this method as synchronized
      In this case its call hangs the VM (see example bellow).
      To prevent the dead lock situation, javadoc should explicitly
      prohibit the synchronization of this method by
      EventQueue object.

      Here is example:

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

      public class Test06 {

          public static void main (String[] args) {
              EventQueue queue1 = new EventQueue();
              PublicEventQueue queue2 = new PublicEventQueue();
              queue1.push(queue2);
              SomeEventToWait event = new SomeEventToWait();
              queue2.postEvent(event);
              queue2.pop();
              System.out.println("OKAY");
              System.exit(0);
          }
      }

      class PublicEventQueue extends EventQueue {

      // public void pop() throws EmptyStackException {
          public synchronized void pop() throws EmptyStackException {
              super.pop();
          }
      }

      class SomeEventToWait extends java.awt.event.ActionEvent implements java.awt.ActiveEvent {
          public SomeEventToWait() {
              super("",0, "action");
          }
        
          public void dispatch() {
          }
      }
      --- Output ---
      %/set/jdk-builds/JDK1.4.0beta-b61/solaris/bin/java Test06
      ^C%

      If we uncomment
      public void pop() throws EmptyStackException {
      string in the test, then output is:
      %/set/jdk-builds/JDK1.4.0beta-b61/solaris/bin/java Test06
      OKAY
      %




      ======================================================================

            sharonz Sharon Zakhour (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: