java basic tutorialThe column introduces how to learn Java lock with Netty

##Recommended (free): java basic tutorial
1 Lock objects and scope
- Reduce the granularity
-

2 The size of the lock object itself
- Reduce space occupation
-
Atomic long V.S long
The former is an object, including an object header to save hashcode, lock and other information. It occupies 16 bytes under a 64-bit system. Under a 64-bit system:
volatile long= 8 bytes - AtomicLong = 8 bytes (volatile long) 16bytes (object header) 8 bytes (reference) = 32 bytes
- Save at least 24 bytes!
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
4 Choose different concurrency classes for different scenarios
Change according to needs- Close and wait for the shutdown event executor (Event Executor) :
Object.wait/ notify =》 CountDownLatch

- Queue responsible for storing tasks in the Nio Event loop
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment





Atomic long V.S long



