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

Lambda expression in static block causes class initialization to hang

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • None
    • 8
    • hotspot
    • None
    • generic
    • generic

      The following lambda expression when used in a static block causes class initialization to hang. The equivalent anonymous inner class runs with no problems.

      We ran into this bug while converting several of our modules and unit tests to use lambda expressions in place of anonymous inner classes. The following code segment will hang:

          static {
              final CountDownLatch startupLatch = new CountDownLatch(1);

              // The following lambda will cause the application to hang
              Util.startup(() -> {
                  startupLatch.countDown();
              });

              try {
                  startupLatch.await();
              } catch (InterruptedException ex) {}
          }

      where Util.startup spins up a new thread and calls the run method of the Runnable (or closure) that is passed into the method.

      I have attached the complete test program and the thread stack dump.

        1. ClassInitDeadlock.tgz
          2 kB
        2. doit-base-jvmg.log
          11 kB
        3. doit-base-product.log
          8 kB
        4. LambdaBug.zip
          16 kB
        5. LambdaBug-180_b132-fastdebug.log
          11 kB
        6. LambdaBug-180_b132-product.log
          8 kB
        7. lambda-stackdump.txt
          3 kB
        8. threads.base-jvmg.log
          81 kB
        9. threads.base-product.log
          71 kB

            dcubed Daniel Daugherty
            kcr Kevin Rushforth
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: