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

(thread) Threads not garbage collected if constructor fails with an exception

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.1.7, 1.3.1
    • Fix Version/s: None
    • Component/s: core-libs
    • Subcomponent:
    • CPU:
      generic, x86
    • OS:
      generic, windows_2000

      Description

      Name: diC59631 Date: 01/19/99


      This problem has been verified on JDK1.1.7beta2 for
      Digital Unix 4.0c from DEC, on JDK1.1.5K on SunOS 5.5,
      and on Linux_JDK_1.1.5_v7_sbb_unified. It does not seem
      to exist on Sun JDK/Symantec JIT on Win32.

      If a thread is created and throws an exception in its
      constructor, or if the constructor returns but the thread
      is never started, the thread is never garbage collected
      (even when invoking System.gc() explicitly). The first case is
      especially egregious, because there is no valid reference to
      do anything to the thread with.

      Simple code triggering this problem:

      public class test {
        public static void main(String[] args) {
          Broken foo=null;
          while(true){
            try{
      foo = new Broken();
      foo.start();
            }
            catch (Exception e){
      System.err.println("caught exception");
            }
            System.gc();
          }
        }
      }

      class Broken extends Thread{
        Broken()
          throws Exception {
            sleep(1000);
            throw new Exception("hi");
        }

        public void run(){
        }
      }

      Attaching a debugger to this code will show an ever
      increasing list of zombie threads:
       9. (Broken)0x6e314698 Thread-5 zombie
      10. (Broken)0x6e303c68 Thread-6 zombie
      11. (Broken)0x6e314658 Thread-7 zombie
      12. (Broken)0x6e314620 Thread-8 zombie
      13. (Broken)0x6e3146c0 Thread-9 zombie
      14. (Broken)0x6e314238 Thread-10 zombie
      15. (Broken)0x6e3146f0 Thread-15 zombie
      16. (Broken)0x6e313fc8 Thread-16 zombie

      The problem will also be encountered if the
      exception is not thrown and the start() call is
      never made.
      (Review ID: 41109)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              iris Iris Clark
              Reporter:
              dindrigo Daniel Indrigo (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: