Home  >  Article  >  Java  >  What is the concept of java CAS

What is the concept of java CAS

WBOY
WBOYforward
2023-05-03 21:34:051587browse

1. Description

When multiple threads perform CAS operations on a resource at the same time, only one thread succeeds, but it will not block other threads, and other threads will only receive A signal that the operation failed. It can be seen that CAS is actually an optimistic lock.

2. Example

Following the AtomInteger code, we can find that sum.misc.Unsafe is ultimately called. Look at the name Unsafe, it's an unsafe class that exploits just the right holes in Java's class and visibility rules. For the sake of speed, Unsafe makes some compromises on Java's security standards.

public final native boolean compareAndSwapInt(Object var1, long var2, int var4, int var5);

These CAS methods should use local methods. Therefore, we need to search the source code of jdk ourselves for the specific implementation of these methods.

What are the characteristics of Java

1. As a representative of static object-oriented programming language, Java language implements object-oriented theory and allows programmers to perform complex programming with an elegant way of thinking.

2.Java has the characteristics of simplicity, object-oriented, distributed, security, platform independence and portability, and dynamic nature.

3. Use Java to write desktop applications, Web applications, distributed systems and embedded system applications, etc.

The above is the detailed content of What is the concept of java CAS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete