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

Semaphore acquire method can hang.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 6u19
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_19"
      Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
      Java HotSpot(TM) 64-Bit Server VM (build 16.2-b04, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7600]

      A DESCRIPTION OF THE PROBLEM :
      I was enountering a hang in some code and it turned out that it was occuring on a call to Semaphore.acquire(). This occurs when you release past Integer.MAX_VALUE permits. I was able to put together a small script that reproduces the problem. I realize that this may not be the intended usage, and it's probably an edge condition, but, In my opinion, if Semaphore cannot handle releasing past that value, it should inform the user by throwing an exception.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Semaphore constructed
      Semaphore released
      Semaphore released again
      Semaphore acquired
      ACTUAL -
      Semaphore constructed
      Semaphore released
      Semaphore released again

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.concurrent.Semaphore;

      class SemaphoreTest {
          public static void main(final String[] args) {
              Semaphore semaphore = new Semaphore(Integer.MAX_VALUE);
              System.out.println("Semaphore constructed");
              semaphore.release();
              System.out.println("Semaphore released");
              semaphore.release();
              System.out.println("Semaphore released again");
              try {
                  semaphore.acquire();
              } catch (Throwable e) {
                  System.out.println("Exception encountered");
                  e.printStackTrace();
              }
              System.out.println("Semaphore acquired");
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't release past Integer.MAX_VALUE...

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dholmes David Holmes
                Reporter:
                ndcosta Nelson Dcosta (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: