[concurrency-interest] CHM.compute restrictions (was: no subject)

Doug Lea dl at cs.oswego.edu
Mon Aug 6 10:31:55 EDT 2018


On 08/06/2018 10:10 AM, David Stuebe via Concurrency-interest wrote:
> Hey folksĀ 
> 
> Attempted to post this last week while I was joining the list. 

To reduce spam, non-member posts are silently dropped. Sorry.

> 
> I am using a ConcurrentHashMap.compute operation in an outer
> Stream.parallel forEach operation. A library used in the compute method
> also uses Stream.parallel.
> 
> I have written a test that illustrates the issue and explores different
> implementations in 215 lines of code.
> https://gist.github.com/dstuebe/89361f64dc44a935e53d0a49f149317c#file-nestedparallel-java
> 
> The code deadlocks with the following stack trace:
> https://gist.github.com/dstuebe/89361f64dc44a935e53d0a49f149317c#file-stacktrace-txt
> 
> I do not understand why line 87 (the compute block) appears to be called
> recursively leading to deadlock when I use Stream.parallel for the outer
> loop.

A recursive CHM.compute call appears to invoked while trying to
initialize the contents of an element in the same map, which is
disallowed in general, but sometimes works anyway. In most other cases,
CHM successfully detects this and throws an exception, but it cannot
catch all of them.

-Doug






More information about the Concurrency-interest mailing list