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

fp.bugs 3091 thread.start() does not start thread once stopped, but run() will

XMLWordPrintable

    • sparc
    • solaris_2.4

      To followup on this bug, please contact ###@###.###

      This one comes from a customer.
      >From: ###@###.### (Robert Uomini)
      BugReport applet gives buttons to start and stop a thread 'WaitThread'.
      I've added a button to test the suggested workaround ( start+run ) as
      well. The thread is a thread subclass that prints to stdout in
      3-second intervals. Thread.start() does not cause the thread to become
      active- this seems to happen only if run() is given, which causes some
      strange I/O lockup.

      _____Customer Report Begins_____
      Bug: 2.0 Beta (JDK), Java

      Severity: painful

      Configuration: Sparc5, Solaris 2.4

      Description of problem: stopped Threads do not get restarted unless run()
      is called.

      What happens: In the attached example, a thread is created which executes
      a three-second wait in a loop. When the thread is stopped and restarted
      via start(), the run() method fails to execute unless it is called
      explicitly (try uncommenting the call to wait_thread.run() in the sample
      code); in this case, run() gets called twice.
      _____End Customer Report_____
       
      _____ Begin Customer Code ( with minor SQE addition )_____
      // BugReport.java
      import java.awt.*;

      public class BugReport extends Frame
        {
        Panel panel;

        Button button1;
        Button button2;
        Button button3;

        WaitThread wait_thread;

        int windowWidth = 300;
        int windowHeight = 150;

        public BugReport(String args[])
          {
          super("Bug Report");

          panel = new Panel();
          button1 = new Button("Stop thread");
          button2 = new Button("Start thread");
          button3 = new Button("Run thread");

          panel.add(button1);
          panel.add(button2);
          panel.add(button3);
          add("South", panel);

          wait_thread = new WaitThread(this);
          wait_thread.start();

          resize(windowWidth, windowHeight);
          pack();
          show();
          }

        public synchronized boolean action(Event evt, Object arg)
          {
          if (evt.id == Event.ACTION_EVENT)
            {
            if ("Stop thread".equals(evt.arg))
      {
      System.out.println("Stopping thread");
      wait_thread.stop();
      return true;
      }
            if ("Start thread".equals(evt.arg))
      {
      System.out.println("Starting thread");
      wait_thread.start();
      // wait_thread.run();
      return true;
      }
      // Run Thread button and functionality were added by J. Hagen
            if ("Run thread".equals(evt.arg))
      {
      System.out.println("Running thread");
      wait_thread.start();
      wait_thread.run();
      return true;
      }
            }
          return true;
          }

        public static void main(String args[])
          {
          new BugReport(args);
          }
        }


      // WaitThread.java
      import java.awt.*;

      public class BugReport extends Frame
        {
        Panel panel;

        Button button1;
        Button button2;
        Button button3;

        WaitThread wait_thread;

        int windowWidth = 300;
        int windowHeight = 150;

        public BugReport(String args[])
          {
          super("Bug Report");

          panel = new Panel();
          button1 = new Button("Stop thread");
          button2 = new Button("Start thread");
          button3 = new Button("Run thread");

          panel.add(button1);
          panel.add(button2);
          panel.add(button3);
          add("South", panel);

          wait_thread = new WaitThread(this);
          wait_thread.start();

          resize(windowWidth, windowHeight);
          pack();
          show();
          }

        public synchronized boolean action(Event evt, Object arg)
          {
          if (evt.id == Event.ACTION_EVENT)
            {
            if ("Stop thread".equals(evt.arg))
      {
      System.out.println("Stopping thread");
      wait_thread.stop();
      return true;
      }
            if ("Start thread".equals(evt.arg))
      {
      System.out.println("Starting thread");
      wait_thread.start();
      // wait_thread.run();
      return true;
      }
            if ("Run thread".equals(evt.arg))
      {
      System.out.println("Running thread");
      wait_thread.start();
      wait_thread.run();
      return true;
      }
            }
          return true;
          }

        public static void main(String args[])
          {
          new BugReport(args);
          }
        }

       public class WaitThread extends Thread
        {
        BugReport parent;

        public WaitThread(BugReport parent)
          {
          super();
          this.parent = parent;
          }

        public synchronized void run()
          {
          for(int i = 0; i >= 0; i++)
            {
            System.out.println("In WaitThread");
            try
      {
      wait(3000);
      }
            catch (InterruptedException e);
            }
          }
        }

            tlindholsunw Timothy Lindholm (Inactive)
            vssriniv Vijay Srinivasan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: