java basic tutorialThe column introduces how to learn Java lock with Netty
##Recommended (free): java basic tutorial
1 Lock objects and scope
2 The size of the lock object itself
3 Lock speed
Improve concurrencyLongCounter
Used for functions such as recording the number of bytes of memory allocation. Under high concurrency: java.util.concurrent.atomic.AtomicLong => java.util.concurrent.atomic.LongAdder
According to different situations, choose different concurrent package implementations
JDK< 1.8 Consider ConcurrentHashMapV8 (the version of ConcurrentHashMap in jDK8)
4 Choose different concurrency classes for different scenarios
Change according to needs Object.wait/ notify =》 CountDownLatch
Jdk's LinkedBlockingQueue (MPMC, multi-producer Multiple consumers) -> jctools' MPSC
io.netty.util.internal.PlatformDependent.Mpsc#newMpscQueue(int):
5 The value of lock
If you can’t use it, don’t use it In Netty application scenarios: partial serial and overall parallel>--one queue and multiple threads mode:
Reduce the difficulty of user development, simplify logic, and improve processing performance
Avoid the additional overhead of context switching and concurrency protection caused by locks
The above is the detailed content of Learn the use of Java locks with Netty. For more information, please follow other related articles on the PHP Chinese website!