Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the knowledge points related to java threads?

Shulou Source: shulou.com Published: 2022-06-01 20:39:07 11月11日 Update

This article mainly explains "what are the knowledge points related to java thread". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. let's study and learn "what are the knowledge points related to Java thread"?

Cas compare and swap (exchange):

Read the current value

Calculated result value

Compare current values with memory values

Update new valu

ABA question, adding additional fields

The underlying primitive lock (hardware lock signal) cmpxchg

Java object memory layout

Object header (markword, class point, on 64-bit system, jvm enables compression to 4 bytes, does not enable to 8 bytes), (array length-4 bytes) instance data, alignment (improves efficiency by system bus bits), as shown below

Lock up (downgrade) process

New- > bias lock-> lightweight lock (no lock, spin lock, adaptive spin lock)-> weight lock

Bias lock (default delay 4 seconds plus)-> add a pointer to the lock object in the object's markword

Lightweight locks-> contending threads contend to point to the lock object in the way of cas

Heavy lock-> user mode applies for system lock from kernel mode, and all other competing threads are queued after the application (reduce resource consumption)

Lock downgrade: it usually occurs in the case of gc, so the downgrade is meaningless at this time

Lock elimination: implicit elimination of internal locks when references are not called by other threads

Lock coarsening: value lock outermost operation (such as while (I) for the same operation on a set of objects

Tags: Thread object knowledge knowledge point barrier cache memory byte system learning competition code content situation pointing efficiency data lightweight lightweight process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Shulou Technology MySQL Linux MariaDB