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

Object.{wait,notify}() should support a new QUEUE/CONDITION parameter

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.2.2
    • core-libs
    • x86
    • windows_95

      Name: mc57594 Date: 11/15/99


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, native threads, symcjit)


      The wait() and notify() methods should have a new Condition parameter, so that,
      you can wait in different queues for different conditions. Example:

      class Consumer {
         ...
         if (num_elements == 0 )
               wait (production);

         <consume the element>

         --num_elements;
         notify (consumption)
         ...
      }

       


      class Producer {
         ...
         if (num_elements == MAX )
               wait (consumption);

         <produce the element>

         ++num_elements;
         notify (production)
         ...
      }



      The code is more clear, you avoid while loops and you avoid to wake up a process
      that doesn't have to be notified. This is the natural way that monitors are
      usually implemented.
      (Review ID: 97799)
      ======================================================================

            martin Martin Buchholz
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: