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

EventQueue.push() does not clear this.queue

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: mgC56079 Date: 04/24/98



      Javadoc says:

          /**
           * Replace the existing EventQueue with the specified one.
           * Any pending events are transferred to the new EventQueue
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           * for processing by it.
             ^^^^^^^^^^^^^^^^^^^^
           *
           * @param an EventQueue (or subclass thereof) instance to be used.
           */
          public synchronized void push(EventQueue newEventQueue) {
              synchronized (newEventQueue) {
                  newEventQueue.queue = queue; // may be null
                  newEventQueue.prev = this;
                  next = newEventQueue;
              }
          }


      ---- Here is the test ----
      import java.util.EmptyStackException;
      import java.awt.*;

      public class EventQueueTest1 {
        public static void main(String[] args) {
          EventQueue q1=new EventQueue();
          EventQueue q2=new EventQueue();
          LockDispatchThreadEvent locker1=new LockDispatchThreadEvent();
          LockDispatchThreadEvent locker2=new LockDispatchThreadEvent();

          // stop q1's dispatch thread.
          q1.postEvent(locker1);

          // this event will not be dispatched by q1 (dispatch thread is locked)
          q1.postEvent(new SomeEvent());

          // disable q2's dispatch thread.
          q2.postEvent(locker2);

          // wait until both threads are locked
          while (! (locker1.isDispatched() && locker2.isDispatched())) {
            Thread.yield();
          }

          // now push q2. Unprocessed SomeEvent should be passed to q2
          // (and should never be processed). However it will be processed by q1
          q1.push(q2);
          
          // unlock q1
          locker1.setLocked(false);

        }

      }

      class LockDispatchThreadEvent extends AWTEvent implements ActiveEvent {
        public LockDispatchThreadEvent() {
          super("",0);
        }

        boolean dispatched=false;
        boolean locked=true;

        public synchronized boolean isDispatched() {
          return dispatched;
        }

        public synchronized void setLocked(boolean locked) {
          this.locked=locked;
          notify();
        }

        public synchronized void dispatch() {
          dispatched=true;
          // this will disable dispatch thread
          while (locked) {
            System.out.println("Dispatch thread stopped: "+Thread.currentThread());
            try {
              wait();
            }
            catch (InterruptedException e) {
            }
          }
          System.out.println("Dispatch thread resumed: "+Thread.currentThread());

        }

      }

      class SomeEvent extends AWTEvent implements ActiveEvent {
        public SomeEvent() {
          super("",0);
        }

        public void dispatch() {
          System.out.println("Test failed: SomeEvent dispatched by "+Thread.currentThread());
        }

      }
      ---- Sample run ----
      % java EventQueueTest1
      Dispatch thread stopped: Thread[AWT-EventQueue-0,5,main]
      Dispatch thread stopped: Thread[AWT-EventQueue-1,5,main]
      Dispatch thread resumed: Thread[AWT-EventQueue-0,5,main]
      Test failed: SomeEvent dispatched by Thread[AWT-EventQueue-0,5,main]
      ^C


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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dmendenhsunw David Mendenhall (Inactive)
              Reporter:
              mgorshen Mikhail Gorshenev (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: