Differences between Java--synchronized and Lock and examples of their use
1. Classification of Java locks (reference link: https://tech.meituan.com/2018/11/15/java-lock.html )
(1) Optimistic lock VS pessimistic lock:
* * optimistic Lock: * * Lock the data first to ensure that the data will not be modified by other threads. The synchronized keyword and the implementation class of Lock are pessimistic locks. It is su ...
Added by deepakagrawal1982 on Sat, 26 Feb 2022 05:43:46 +0200
Java knowledge needed for work (JUC Lock Learning Paper)
JUC is a part of my job that I don't use very much, but I often get asked about it in a helpless interview, so I'll learn about JUC today.
JUC is all called Java. Util. The concurrent package is a toolkit for Java, so why is JUC a frequent question for interviews? Because JUC includes multithreading, atomicity, locks and other heavy content, i ...
Added by UQ13A on Sat, 05 Feb 2022 19:04:49 +0200
Chapter 3 - management of shared model
Chapter 3 - management of shared model (4)
Thread state
Re understand thread state transition (key)
Suppose there is a thread Thread t
Case 1 new -- > runnable
When the t.start() method is called, new -- > runable
Case 2 runnable < – > waiting
After the t thread obtains the object lock with synchronized(obj)C ...
Added by tave on Thu, 03 Feb 2022 12:19:48 +0200
CAS operation and underlying implementation of JUC concurrent programming
concept
The full name of CAS is Compare And Swap, which means compare and exchange. It is the atomic operation of CPUCAS is an abstract idea, not a concrete implementationCAS operation has three parameters: memory address of the value to be modified, expected value and new valueThe main idea is to judge whether the value of a location in memor ...
Added by crash58 on Wed, 26 Jan 2022 06:06:35 +0200
JAVA Concurrent Programming -- thread waiting wake-up mechanism and LockSupport
1. Overview of thread waiting wake-up mechanism2. The wait and notify methods in the object class implement thread waiting and wake-up3. The await post signal method in the condition interface realizes thread waiting and wake-up4. Restrictions on the use of object and Condition5. Introduction to locksupport class6. park wait and unpark wake-up ...
Added by maxsslade on Sun, 26 Dec 2021 18:31:49 +0200
Common locks of JUC
1, AtomicInteger/**
* @author Java And algorithm learning: Monday
*/
public class AtomicInteger {
//No volatile
public AtomicInteger count = new AtomicInteger(0);
//No synchronized
public void m() {
for (int i = 0; i < 1000; i++) {
//count++
count.incrementAndGet();
}
}
pub ...
Added by pt4siek on Wed, 15 Dec 2021 14:08:25 +0200
locks of Java Concurrent Programming
Locks are used to control how multiple threads access shared resources. Generally speaking, a Lock can prevent multiple threads from accessing shared resources at the same time (but some locks can allow multiple threads to access shared resources concurrently, such as read-write locks). Before the emergence of the Lock interface, Java progra ...
Added by tylerdurden on Sat, 02 Oct 2021 03:20:15 +0300
ReentrantLock introduction and AQS source code
Lock
Lock is the core tool in J.U.C. its function is the same as synchronized explained earlier. It is also used to solve thread safety problems in multithreaded environment. In the J.U.C package, the lock mechanism is used in many places.
J. The full name of U.C is java.util.concurrent. It is a common toolkit in concurrent programming. Th ...
Added by pixelsoul on Sat, 04 Sep 2021 23:11:06 +0300