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

(spec thread) Thread.State or related doc should clarify valid notifyAll() behavior

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Not an Issue
    • Affects Version/s: 5.0
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      what's thread state after it goes out of wait set but cannot win the competition for lock ? the following code gives different answer on Solaris and Windows XP:

      class State {

      public static void main(String[] args) throws Exception {

      Thread[] ta = new Thread[10];

      for (int i=0; i<10; i++) {
      ta[i] = new Thread() {
      public void run() {
      synchronized(Object.class) {
                                      System.out.println(Thread.currentThread().getName() + " enter");
      try {
              Object.class.wait();
      } catch(Exception e) {
      e.printStackTrace();
      }
                                      System.out.println(Thread.currentThread().getName() + " get lock");
      for(;;);
      }
                               }
                       };
      ta[i].start();
      }
      Thread.sleep(3000);
      synchronized(Object.class) {
      Object.class.notifyAll();
      }

      Thread.sleep(3000);
      for(int i = 0; i< ta.length; i++) {
      System.out.println(ta[i].getName() + " : " + ta[i].getState());
      }

      }
      }

      On both Solaris and Windows, only one thread is RUNNABLE after notifyAll() is called. but on Solaris, the states of other threads are all WAITING while on Windows, the states are all BLOCKED. As a result, use code depending on Thread.State will not write once, run anywhere. it will has different behaviour on different platforms.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                chegar Chris Hegarty
                Reporter:
                mleisunw Mike Lei (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: