Detailed explanation of Atomic class and Unsafe magic class of concurrent programming
Catalogue of series articles
1: Computer model & detailed explanation of volatile keyword 2: Lock system in java 3: synchronized keyword explanation 5: Atomic atomic class and Unsafe magic class
preface
It can be seen from the previous article. volatile keyword and synchronize keyword can help us solve the problem of data sec ...
Posted by iambradn on Thu, 14 Oct 2021 11:14:46 -0700
Thread pool principle
Thread pool
If too many threads are created in the JVM, the system may run out of resources due to excessive memory consumption or "excessive switching".
In order to solve this problem, the first thought is pooling, so there is the concept of thread pool.
The core logic of the thread pool is to create several threads in advanc ...
Posted by desolator on Sun, 10 Oct 2021 16:16:47 -0700
Concurrent HashMap for Java Concurrent Programming
JDK1.7
First, the data is stored section by section, and then each section of data is equipped with a lock. When a thread occupies the lock to access one section of data, the data of other sections can also be accessed by other threads.
ConcurrentHashMap is composed of Segment array structure and HashEntry array structure.
Segment is a r ...
Posted by mika79 on Tue, 05 Oct 2021 13:46:31 -0700
Java Concurrent Programming -- detailed explanation of common methods
start() and run()
explain
The start() method is used to start a thread. When a thread calls the start() method, it means that the thread enters the ready state and waits for thread scheduling
The run() method is just a common method of the Thread class, which holds the work that the Thread needs to complete]
difference
The start() method i ...
Posted by justoneguy on Sun, 03 Oct 2021 13:55:49 -0700
akka entry series - 5. Routing messages
5. Routing messages
In the previous example, we created and used a single actor, and an actor can only process one message at the same time, which does not give play to the advantages of akka parallel computing. We hope to process messages in parallel, just like kafka's consumer. This requires the use of routing to akka.
Routing is the same a ...
Posted by dmb on Mon, 27 Sep 2021 22:14:44 -0700
Atomic integer, reference, array, updater - JUC - Concurrent Programming (Java)
1, Atomic integer
JUC also provided:
AtomicBooleanAtomicIntegerAtomicLong
Let's take AtomicInteger as an example to understand the common API s. All operations are atomic.
Self increasing:
incrementAndGet(): Auto increment and get, equivalent to + + igetAndIncrement(): get and auto increment, equivalent to i++ Self subtraction
dec ...
Posted by metalblend on Sun, 26 Sep 2021 20:22:29 -0700
Unsafe solution of Java collection class under multithreading
2, Collection class unsafe
2.1ArrayList thread is unsafe
2.1.1 example
Single thread
public class NotSafeDemo {
//Single thread is safe
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
list.forEach(System.out::println);
}
}
a
b
c
Multithreading
public class NotS ...
Posted by coffeehead on Sat, 25 Sep 2021 04:51:09 -0700
Concurrent Programming-07.Atominc Atom Package and Unsafe Magic Classes
1. Atominc Atom Package
There are 12 classes in the Atomic package, and there are four ways to update atoms: the basic type of atomic update, the array, the reference, and the field. The classes in the Atomic package are basically wrapper classes implemented using Unsafe.
Basic Classes: AtomicInteger, AtomicLong, AtomicBoolean
Reference type ...
Posted by Cragsterboy on Thu, 23 Sep 2021 09:10:56 -0700
Usage and scenarios of CountDownLatch, cyclicBarrier and semaphore
preface
In the previous two articles Synchronization queue for AQS,Conditional queue This article is to take a look at the three main concurrency tool classes in JUC: countDownLatch, cyclicBarrier and semaphore. This article will not expand from the perspective of source code as in the previous two articles, but take a look at the usage me ...
Posted by ChompGator on Mon, 20 Sep 2021 10:12:29 -0700
Concurrent programming: asynchronous call to get return value
Hello, I'm Xiao Hei, a migrant worker who lives on the Internet.
Runnable
When creating a Thread, you can use the new Thread(Runnable) method to encapsulate the task code in the run() method of Runnable, submit the Runnable to the Thread as a task, or use the execute(Runnable) method of the Thread pool for processing.
public class RunnableDe ...
Posted by satyricon on Sun, 19 Sep 2021 23:21:32 -0700