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.
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.
- relates to
-
JDK-8281371 Deadlock in lambda expression when used as static initializer in class constructor
-
- Closed
-