Why is there a ConcurrentSkipListMap but an unsynchronized version?

Most of the classes in the Java Collections Framework are not synchronized by default, but can be turned into something synchronized if you need to be thread safe. Synchronization has a performance limitation, so if you are writing something that shouldn't be thread safe, you are better off working with the unsynchronized version.

But it ConcurrentSkipListMap

doesn't follow this pattern. There is no unsynchronized version. Why isn't there faster unsynchronized SkipListMap

for apps that don't require thread safety, consistent with the rest of the Framework Collections?

All I can think of is that the simplest implementation of List Skip is already thread safe, so there would be no performance penalty for the synchronized version. It will make some sense, but looking at the source code doesn't quite carry it over. Although there are no blocks in the code synchronized

, the Javadoc starts with

This class implements a parallel variant of SkipLists ...

which suggests that he is trying to change the algorithm to make it thread safe. Later we read

The basic idea in these lists is to mark the "next" pointers of remote nodes when deleting to avoid conflicts with parallel inserts ...

which also sounds like there is some kind of overhead.

Is it just that this overhead is so small that it's not worth having a non-thread safe SkipListMap

?

+3


source to share


1 answer


ConcurrentSkipListMap is an unlocked CAS operations based implementation. In theory, you shouldn't have to pay a performance penalty if you only use it on one thread. There is no synchronization. When a conflict occurs, rather than blocking the implementation, it essentially loops to resolve the conflict. If not approved, there are no cycles.



-1


source







All Articles