[concurrency-interest] Java 8 CompletableFuture.thenCombine() hangs

Doug Lea dl at cs.oswego.edu
Wed Apr 2 07:01:45 EDT 2014


On 04/01/2014 08:32 PM, Dennis Sosnoski wrote:
> Thanks for confirming it, Martin.
>
> Should I create a bug report against Java 8, or will you just handle this
> directly, Doug?

We'll track it down. Thanks for reporting this!

-Doug


>
>    - Dennis
>
> On 04/02/2014 01:04 PM, Martin Buchholz wrote:
>> Thanks for finding this stress test for java.util.concurrent.
>> Looks like a bug to me - I can reproduce it.
>> Could be in hotspot, fork/join, or CompletableFuture.
>> Doug is by far the best person to investigate.
>>
>> Here's the relevant stack portion:
>>
>> "ForkJoinPool.commonPool-worker-1" #150 daemon prio=5 os_prio=0
>> tid=0x000000000253c000 nid=0x6237 waiting on condition [0x00007f8513390000]
>>    java.lang.Thread.State: TIMED_WAITING (parking)
>> at sun.misc.Unsafe.park(Native Method)
>> - parking to wait for  <0x00000000ec50c120> (a java.util.concurrent.ForkJoinPool)
>> at java.util.concurrent.ForkJoinPool.awaitWork(ForkJoinPool.java:1756)
>> at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1696)
>>
>> "main" #1 prio=5 os_prio=0 tid=0x00000000021ed000 nid=0x613d waiting on
>> condition [0x00007f852a508000]
>>    java.lang.Thread.State: WAITING (parking)
>> at sun.misc.Unsafe.park(Native Method)
>> - parking to wait for  <0x00000000ec50c518> (a
>> java.util.concurrent.CompletableFuture$WaitNode)
>> at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
>> at
>> java.util.concurrent.CompletableFuture$WaitNode.block(CompletableFuture.java:271)
>> at java.util.concurrent.ForkJoinPool.managedBlock(ForkJoinPool.java:3226)
>> at java.util.concurrent.CompletableFuture.waitingGet(CompletableFuture.java:319)
>> at java.util.concurrent.CompletableFuture.join(CompletableFuture.java:2292)
>>
>>
>>
>> On Tue, Apr 1, 2014 at 4:16 PM, Dennis Sosnoski <dms at sosnoski.com
>> <mailto:dms at sosnoski.com>> wrote:
>>
>>     I've run into a situation with CompletableFuture.thenCombine() hanging
>>     (i.e., the returned future never completing even though the original
>>     future and the combined one have completed) with the Oracle Java 8 release
>>     for 64-bit Linux. I wanted to run this by the group before creating a bug
>>     report to make sure I'm not misunderstanding how this is supposed to work.
>>     Here's the code:
>>
>>     public class CompletableFutureFail {
>>
>>         private Supplier<Integer> newLambda(int i) {
>>             return () -> Integer.valueOf(i);
>>         }
>>
>>         private Integer run(int n) {
>>             CompletableFuture<Integer> last =
>>     CompletableFuture.supplyAsync(newLambda(0));
>>             for (int i = 1; i < n; i++) {
>>                 last = CompletableFuture.supplyAsync(newLambda(i))
>>     .thenCombine(last, Math::max);
>>             }
>>             return last.join();
>>         }
>>
>>         public static void main(String[] args) {
>>             CompletableFutureFail fail = new CompletableFutureFail();
>>             for (int i = 0; i < 100; i++) {
>>                 fail.run(10000);
>>                 System.out.println("Did it " + i);
>>             }
>>         }
>>     }
>>
>>     When I run it from the command line it mostly doesn't make it through the
>>     first call to run(). Sometimes it does, but it generally only makes a few
>>     passes before hanging. In other circumstances (such as running inside
>>     Eclipse) I've seen it make it all the way through to the end, though most
>>     often it also hangs there in the first few passes. I'm thinking it might
>>     be Hotspot related because of the halting pattern.
>>
>>     Any suggestions?
>>
>>     Thanks,
>>
>>       - Dennis
>>
>>     _______________________________________________
>>     Concurrency-interest mailing list
>>     Concurrency-interest at cs.oswego.edu <mailto:Concurrency-interest at cs.oswego.edu>
>>     http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
>>
>
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>



More information about the Concurrency-interest mailing list