Is the thread safe but does not prevent a dead end?

I came across this line, which reads: "However, despite the fact that all operations are thread safe, the search operations do not entail locking, and there is no support for locking the entire table in such a way as to prevent all access" to the general description of the class Java [ConcurrentHashMap] ( https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ConcurrentHashMap.html ). My question is: does this mean that ConcurrentHasMap does not prevent deadlock? Also, I thought that from the point of view of the ceiling, it is understood that the dead castle will not take place?

+4
source share
2 answers

You get things wrong: when you create a project that requires locking, you open the door to dead locks.

This does not necessarily mean that any such architecture in itself is vulnerable to dead castles.

Example: a typical deadlock situation is when thread A has an L1 lock and expects an L2 lock; while the thread B contains L2 and needs L1. If you have only one lock object, then this scenario is one .. this cannot happen.

In other words: you are not using class X, this will prevent deadlocks. It's impossible. If at all, you can use class X because it offers you functionality that allows you to create a "guaranteed-no-lock" design!

+5

, , .. . ( ).

ConcurrentHashMap , , , . , .


, , . , . - .

Wikipedia.

+4

Source: https://habr.com/ru/post/1658697/


All Articles