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

need to clarify which EventQueue is useb by invokeLater/invokeAndWait

    • b73
    • sparc
    • solaris_2.6
    • Verified

      Name: ktR10099 Date: 03/04/2002


      According to specification for method EventQueue.invokeAndWait() "Causes
      runnable to have its run() method called in the dispatch thread of the
      EventQueue. This will happen after all pending events are processed. The
      call blocks until this has happened." Current jdk implementation
      demonstrates wrong behavior. PLease find below example, demonstrating the
      bug:
      ------------------------test82.java-------------------------------
      import java.awt.*;
      import java.awt.event.*;

      public class test82 {
          public static void main(String[] args) {
              EventQueue eq = new EventQueue();
              NewActionEvent nae1 = new NewActionEvent(10000);
              NewActionEvent nae2 = new NewActionEvent(5000);
              NewActionEvent nae3 = new NewActionEvent(1000);
              eq.postEvent(nae1);
              eq.postEvent(nae2);
              eq.postEvent(nae3);
              try {
                  eq.invokeAndWait(new Runner(-1));
              } catch(Exception e) {
                  System.out.println("Unexpected Exception : " + e);
              }
              System.out.println("finished");
          }
      }

      class NewActionEvent extends InvocationEvent {
          int delay;

          public NewActionEvent(int delay) {
              super(new Object(), new Runner(delay));
              this.delay = delay;
          }

          public synchronized void dispatch() {
              super.dispatch();
              try {
                  Thread.sleep(delay);
              } catch(InterruptedException ie) {
              }
              System.out.println("dispatched with delay " + delay);
          }
      }

      class Runner implements Runnable {
          int delay;

          public Runner(int delay) {
              this.delay = delay;
          }

          public void run() {
              System.out.println("called run() with delay " + delay);
          }
      }
      ---------------------output of test82 under jdk1.4.1-----------------
      called run() with delay 10000
      called run() with delay -1
      finished
      dispatched with delay 10000
      called run() with delay 5000
      dispatched with delay 5000
      called run() with delay 1000
      dispatched with delay 1000
      ---------------------------------------------------------------------
      ======================================================================

            son Oleg Sukhodolsky (Inactive)
            kvtsunw Kvt Kvt (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: