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

java.lang.Thread.stop() hangs when stopping a blocked thread

    XMLWordPrintable

Details

    • sparc
    • solaris_2.5

    Description



      Name: akC45999 Date: 11/27/96


       Two threads aquire their own monitors and then thats of each other,
      so deadlock occurs. The third thread attempts to stop them
      and hangs itself.


      -------------------------- t_0.java ------------------------------
      interface t_0 {

       public void aquire_self ();
       public void aquire_peer ();

      }

      -------------------------- invokeinterface02301.java ------------------------------
      public class invokeinterface02301 extends Thread implements t_0 {

        t_0 t;

        static java.io.PrintStream out;

        public static void trace (String msg) {
      out.println(Thread.currentThread().getName()+": "+msg);
        }

        public void run () {
      trace("attempt to aquire_self");
      aquire_self();
        }

        public synchronized void aquire_self () {
      trace("self aquired");
      try {
      sleep(100);
      } catch (InterruptedException e) {
      out.println("InterruptedException:");
      }
      trace("attempt to aquire_peer:"+t);
      t.aquire_peer();
        }

        public synchronized void aquire_peer () {
      trace("peer aquired");
        }

        public static int run (String argv[], java.io.PrintStream out_p)
        {
      out=out_p;
      invokeinterface02301
      th1=new invokeinterface02301()
      ,th2=new invokeinterface02301()
      ;
      th1.t=th2;
      th1.setName("thr 1");
      th2.t=th1;
      th2.setName("thr 2");
      th1.start();
      th2.start();
      try {
      sleep(300);
      } catch (InterruptedException e) {
      out.println("InterruptedException:");
      }
      trace("game over");
      int res=2;
      if (th1.isAlive()) {
      trace("th1 isAlive");
      th1.stop();
      trace("th1 stopped");
      res--;
      }
      if (th2.isAlive()) {
      trace("th2 isAlive");
      th2.stop();
      trace("th2 stopped");
      res--;
      }
      if (res==1) {
      out.println("something wrong");
      res=2;
      }
      return res;
        }

        public static void main(String argv[])
        {
           System.exit(run(argv,System.out));
        }

      }
      ----------------------- output ----------------------------------
      thr 1: attempt to aquire_self
      thr 1: self aquired
      thr 2: attempt to aquire_self
      thr 2: self aquired
      thr 1: attempt to aquire_peer:Thread[thr 2,5,main]
      thr 2: attempt to aquire_peer:Thread[thr 1,5,main]
      main: game over
      main: th1 isAlive

      -----------------------------------------------------------------

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

      Attachments

        Activity

          People

            tlindholsunw Timothy Lindholm (Inactive)
            rfqsunw Rfq Rfq (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: