ConcurrentHashMap
is designed to be non-blocking, although some contention is possible if multiple updates to the same hash segment happened simultaneously.- Yes.
Would an inner static runnable in a singleton block if used as wrapper for callables, if it modifies a singleton's static param?
-
25-06-2022 - |
Question
1) Is there a chance that an inner static Runnable
class can block if it modifies a static ConcurrentHashMap
in the outer singleton, after it calls a Callable
? I'm thinking about a scenario where the modification is made to the same item in the map by multiple runnables at the same time. Multiple runnables are ran in a static ThreadPoolExecutor
in the outer singleton.
2) Would the callable be called in the same Thread
as the runnable, if i do a val = myCallable.call()
? It modifies the concurrenthashmap depending on the result of a callable.
Solution
OTHER TIPS
Except when running static initializers, Java will never implicitly block.
call()
is a normal method call and will run synchronously in the calling thread, like any other method call.