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

Dennis Sosnoski dms at sosnoski.com
Thu Apr 3 16:15:56 EDT 2014

On 04/03/2014 09:28 PM, Paul Sandoz wrote:
> I think i may have found the cause, my initial gut feeling was wrong about a race condition :-)
> It appears to be caused by a StackOverflowException being thrown when an async task attempts to complete all its dependent tasks in the completion chain. That exception gets swallowed and does not propagate.
> This behaviour is likely exacerbated because the default F/J pool (common pool) is LIFO-based, so precedence will be given for later tasks to execute before earlier tasks, thus setting up the scenario for a StackOverflowException to occur.
> See example code below, where the first async task will not complete until subsequent async tasks have done so, which creates a very long completion chain.
> Not quite sure how it fix it... might require the use of an explicit stack on the heap, plus it might point to a general weakness in CompletableFuture for handling exceptions thrown by the framework (e.g. OutOfMemoryError).

Better than a race condition, anyway!


   - Dennis

More information about the Concurrency-interest mailing list