Home > Java > javaTutorial > body text

What is the concept of java CAS

WBOY
Release: 2023-05-03 21:34:05
forward
1617 people have browsed it

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);
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template