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

pack() blocks when second thread is running

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P3
    • None
    • 1.0.2
    • client-libs
    • None
    • generic
    • solaris_2.5

    Description

      In the following application (called SystemConsole), the pack() call blocks
      until the second thread terminates. Since the second thread shouldn't be
      interfering with the event dispatch thread, I don't understand why AWT stops
      at this point. (The second thread does run properly.)


      import java.awt.*;
      import java.io.*;

      public class SystemConsole extends Frame {
          private TextArea text;

          public SystemConsole() {
      super("System Console");
      System.err.println("supered");
      text = new TextArea(24, 80);
      System.err.println("created");
      add("Center", text);
      System.err.println("added");
      // Application blocks inside of pack() until ReadStdin terminates.
      pack();
      System.err.println("packed");
      show();
          }

          public boolean handleEvent(Event evt) {
      System.err.println("frame event " + evt);
      if (evt.id == Event.WINDOW_DESTROY) {
      System.exit(0);
      return true;
      }
      return false;
          }

          public static void main(String argv[]) {
      Thread t = new Thread(new ReadStdin());
      t.start();
      System.err.println("new thread started");
      Frame f = new SystemConsole();
      System.err.println("console created");
      //t.stop();
      //System.err.println("new thread stopped");
          }
      }

      class ReadStdin implements Runnable {
          public void run() {
      System.out.println("test system console");
      DataInputStream in = new DataInputStream(System.in);
      String line;
      try {
      while ((line = in.readLine()) != null) {
      System.out.println(line);
      }
      } catch (IOException e) {
      System.out.println("IOException: " + e);
      }
      System.out.println("test done");
          }
      }

      Attachments

        Issue Links

          Activity

            People

              jeff Jeff Dinkins
              bshannon Bill Shannon (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: