Java design fine-grained implementation code based on concurrent HashMap

Fine grained locks:

Several locks in Java: synchronized, reentrantlock and reentrantreadwritelock can basically meet the programming requirements, but their granularity is too large. Only one thread can enter the synchronization block at the same time, which is not applicable to some high concurrency scenarios. For example, bank customers a transfer to B and C transfer to D. if the two threads are concurrent, the code does not need to be synchronized. However, if threads 3 and e transfer money to B at the same time, synchronization must be added to B. At this time, we need to consider the granularity of locks, that is, fine-grained locks.

Some introductory articles about Java fine-grained locks have been searched online, most of which provide ideas, such as optimistic locks and string Intern () and class concurrenthashmap. I am interested in the third kind. Therefore, I studied the source code of concurrenthashmap. The design idea of fine-grained ambition based on concurrenthashmap is as follows:

The above is all about the fine-grained implementation code of Java based on concurrent HashMap. I hope it will be helpful to you. Interested friends can refer to: a brief introduction to the concept and implementation of coarse-grained and fine-grained permission control, an example of filter coarse-grained permission control code in java web design, etc. if there are deficiencies, please leave a message to point out. Thank you for your support!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>