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

Thread state is incorrect during class initialization procedure

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      the Java Language Spec 12.4.2 describes the detail Initalization procedure. The step 2 says

      "2. If initialization is in progress for the class or interface by some other thread,
      then wait on this Class object (which temporarily releases the lock). When
      the current thread awakens from the wait, repeat this step."

      I wrote a small program , it shows the thread state is not Thread.WAIT, it's Thread.RUNNABLE on both solaris and windows. see below. When Thread t tries to read Init.done, the state of t should be WAIT according to language spec. however, it's RUNNABLE in fact.

      class Init{

              static volatile boolean done = false;

              static {
                      Thread t = new Thread() {
                              public void run() {
                                      System.out.println("enter thread");
                                      done = true;
                              }
                      };

                      t.start();

                      while(!done) {
                              try {
                                      Thread.sleep(3000);
                              } catch (Exception e) {}

                              System.out.println("state " + t.getState());
                      }
              }

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

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mleisunw Mike Lei (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: