1, Atomic operation
Let's look at a piece of problem code first
/// Gain self increment
public static void GetIncrement()
long result = 0;
//10 Concurrent execution
1. What is a work queue
Work queue: we can put things that are not very urgent to deal with into the workqueue for processing. When the system is idle, we will execute the things in the workqueue. The essence of work queue is to open a thread to process the arranged tasks, so there can be no dead cycles in the work queue. Do not use API s that ...
Posted by larissahn on Tue, 05 Apr 2022 23:31:05 +0300
Use of thread pool
Labels (space delimited): multithreading
Executors tool class (create pool and submit task)
Through the tool class, you can create a thread pool
Several common thread pool creation methods
Create a thread pool through the static method of Executors
1. Create a thread pool of fixed size (it can be used for instantaneous peak ...
Posted by yacaph on Tue, 05 Apr 2022 06:55:54 +0300
From: Ordinary hope
1. synchronized principle
In java, each object has only one synchronization lock. This also means that synchronization locks are object dependent.When we call the synchronized method of an object, we get the synchronization lock of the object. For example, synchronized(obj) acquires the synchronization lock of "obj ...
Posted by Roberto on Tue, 05 Apr 2022 05:15:08 +0300
Difficulties of asynchronous programming
How to implement asynchronous programming gracefully has always been a difficult problem. The usual method of asynchronous programming is to use the callback method, but this method usually embeds the code in the code of the normal process, and when there are multiple layers of nesting, the code is more ...
Posted by lhale on Mon, 04 Apr 2022 02:26:59 +0300
1, Introduction to singleton mode
1 mode description
Implement one class, only one instantiated object, and provide a global access point
2 role (problem solved)
Ensure that there is only one object in a class to reduce the coupling between objects
3 working principle
In Java, we operate these classes by using objects (after class ins ...
Posted by yuppicide on Mon, 04 Apr 2022 00:57:50 +0300
Semaphore is a thread synchronization structure used to pass signals between threads to avoid signal loss, or to protect a key area like a lock. Since 5.0, jdk has been used in Java util. The official implementation of semaphore is provided in the concurrent package, so you don't need to implement semaphore yourself. However, it is necessary to ...
Posted by Stunt on Mon, 04 Apr 2022 00:30:22 +0300
Part of this article is from the art of Java Concurrent Programming
Any Java Object has a monitor method, mainly including wait(), wait(long timeout), notify() and notifyAll() methods. These methods cooperate with the synchronized synchronization keyword to realize the wait notification mode. The Condition interface also prov ...
Posted by assonitis on Sun, 03 Apr 2022 07:59:12 +0300
Processes and threads
Today, the computers we use have already entered the era of multi CPU or multi-core, and the operating systems we use are operating systems that support "multi task", which enables us to run multiple programs at the same time, or decompose a program into several relatively independent subtasks, so that multiple ...
Posted by stenk on Sun, 03 Apr 2022 02:46:08 +0300
Introduction to concurrent container
Because the synchronization container synchronizes the synchronized added by almost all methods, which ensures the safety of threads, but the cost is to seriously reduce the concurrency performance. When multiple threads compete for the container, the throughput is seriously reduced.
Java5.0 began to redes ...
Posted by linkskywalker on Fri, 01 Apr 2022 23:22:15 +0300