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

Phaser.arrive() throws IllegalStateException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:

      Description

      SYNOPSIS
      --------
      Phaser.arrive() throws IllegalStateException

      OPERATING SYSTEM
      ----------------
      Tested on Windows and Linux

      FULL JDK VERSION
      ----------------
      JDK 7 (b128 onwards)

      PROBLEM DESCRIPTION from LICENSEE
      ---------------------------------
      The attached testcase throws an IllegalStateException when run against JDK 7 b128 or later. This appears to be caused by a timing issue.

      There were two changes in the concurrency code in b128:

      7011857: java/util/concurrent/Phaser/FickleRegister.java fails on solaris-sparc
      7005424: Resync java.util.concurrent classes with Dougs CVS - Jan 2011

      REPRODUCTION INSTRUCTIONS
      -------------------------
      Compile and run the attached testcase.

      Expected behaviour
      Should run forever without throwing an Exception

      Observed behaviour
      An Exception is thrown shortly after the testcase starts, for example:

      java.lang.IllegalStateException: Attempted arrival of unregistered party for java.util.concurrent.Phaser@471e30[phase =
      197942 parties = 2 arrived = 2]
              at java.util.concurrent.Phaser.doArrive(Phaser.java:389)
              at java.util.concurrent.Phaser.arrive(Phaser.java:622)
              at PhaserTest$PhaserTestHelper.run(PhaserTest.java:38)
              at java.lang.Thread.run(Thread.java:732)

      TESTCASE
      --------
      import java.util.concurrent.Phaser;

      public class PhaserTest {
          private Phaser testPhaser = new Phaser();

          public void doTest() {
              Thread[] helpers = new Thread[2];

              for (int i = 0; i < helpers.length; i++) {
                  Thread phaserHelper = new Thread(new PhaserTestHelper(testPhaser));
                  phaserHelper.setName("Thread" + i);
                  helpers[i] = phaserHelper;
              }

              for (int i = 0; i < helpers.length; i++) {
                  helpers[i].start();
              }

              while (true) {
                  if (testPhaser.isTerminated())
                      break;
              }
          }

          public class PhaserTestHelper implements Runnable {
              private Phaser myPhaser;

              public PhaserTestHelper(Phaser phaser) {
                  myPhaser = phaser;
                  myPhaser.register();
              }

              public void run() {
                  while (true) {
                      try {
                          if (myPhaser.isTerminated())
                              break;
                          myPhaser.arrive();
                      } catch (IllegalStateException ise) {
                          ise.printStackTrace();
                          myPhaser.forceTermination();
                          break;
                      }
                  }
              }

          }

          public static void main(String[] args){
              PhaserTest problem = new PhaserTest();
              problem.doTest();
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                dkorbel David Korbel (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: