synchronization queue, when the thread acquires a lock failure (multi-threaded contention resources are blocked when the queue will be entered), threads will be added to the queue tailSummarize:
AQS is only responsible for managing thread blocking queues.
Blocking and waking of threads
The Synchronizer is the key to implementing the lock (for example, the Aqs queue Synchronizer) and uses
Java and the contract to make a general summary, if there is a mistake, please correct me.The overall structure of the JUC package is generally as followsThe outer frame is mainly lock (Reentrantlock, Readwritelock, etc.), synchronizer (semaphores, etc.), blocking queues (blockingqueue, etc.), Executor (thread pool), Concurrent Containers (CONCURRENTHASHMAP, etc.), as well as fork/join framework;The inner layer has the AQS (Abstractqueuedsynchronizer
A preface
Although there have been many predecessors have analyzed Abstractqueuedsynchronizer (referred to as Aqs, also known as queue Synchronizer) class, but feel those points are always someone else's, see again even a few times will not be impressive. So the record is more impressive, but also to discuss with you (this is the advantage of repeating the wheel, but also mainly the length of this article is too long, hesitated for a long time to deci
implementation of the Invoke () method blocks (block) the invocation of the thread, sends the call to the T2, marshal it, executes the call in T2, sends the return value T1, and then returns to the T1 client. The Invoke () method locates the invocation of the method in T2 with an agent and takes an ordinary object array as its argument.
The caller can also check the InvokeRequired property because you can either call ISynchronizeInvoke in the same thread or reposition it (redirect) to another
Java uses httpasyncclient for asynchronous HTTP requestsSome time ago there was a need to complete a statistical business before SPRINGMVC mapping's URL jump. There is a clear need for asynchronous processing, or an error or exception will affect the subsequent page jumps. The asynchronous way is also non-blocking, when the asynchronous call succeeds or not, the program goes down and does not have to wait until the input and output processing is finished before returning.Mainly used in the Httpa
First, prefaceA simple pulse synchronizer has been described in the previous article, which allows for synchronization in simple scenarios, as well as a number of application limitations or drawbacks, such as:(1) It is sensitive to the DST_CLK relation of SRC_CLK domain, and may not adapt when the SRC_CLK and DST_CLK clock frequency differ greatly;(2) because there is no complete handshake mechanism, when the interval between multiple src_pulse is sho
Some time ago there is a need to complete a statistical business before SPRINGMVC mapping URL jump. It is obvious that asynchronous processing is required, otherwise an error or an exception can affect the subsequent page jump. The asynchronous approach is also non-blocking, when the asynchronous call succeeds or the program goes down, and does not have to wait until the input and output processing is completed before returning.
Mainly used to Httpasyncclient-4.0.1.jar,httpclient-4.3.2.jar,httpc
/executor implementation. Fair lock, unfair lock, Condition, Countdownlatch, Semaphore and so on in the back of the space to explain.The complete design principle can be referenced in Doug Lea's paper, the Java. util. concurrent Synchronizer Framework , here do some brief analysis.The basic idea is to represent a Synchronizer that supports the following two operations:Get Lock: First determine whether the c
, Countdownlatch, Semaphore and so on in the back of the space to explain.The complete design principle can be referenced in Doug Lea's paper, the Java. util. concurrent Synchronizer Framework , here do some brief analysis.The basic idea is to represent a Synchronizer that supports the following two operations:Get Lock: First determine whether the current state is allowed to acquire the lock, if it is to ob
Installation and configuration of the Tomcat pluginTomcatplugin plugin Download URL http://www.eclipsetotale.com/ tomcatplugin.html, download a compressed package Tomcatpluginv321.zip unzip to the plugins subdirectory under the Eclipse root directory, so that the installation is complete. Restart Eclipse, if the installation and download are correct, you can see three Tomcat kittens on the toolbar after launching the Eclipse platform, the first one is to start Tomcat, the second is to stop Tomca
of threads, or you can use the Threadponlexecutor class directly for maximum control.Not only should you try not to write your own work queue, but you should also try not to use threads directly. Now the key abstraction is no longer a thread, it used to serve both as a unit of work and as an execution mechanism. Now the unit of work and execution mechanism are separate. Now the key abstraction is the unit of work, called the task. There are two kinds of tasks: runnable and its close relatives c
1. What is read and write lock
It is possible to allow multiple read threads to access at the same time, or locks that are blocked by all read threads and other write threads when the write thread is accessed. Read-write lock in two, divided into a read lock and a write lock, through the separation of read and write locks, so that concurrency compared to the general exclusive lock has been promoted. 2. Read and write lock ownership package
Package java.util.concurrent.locks;
3. Read-write l
Aqs Source DetailedSource Analysis Dimension: Synchronization queue, exclusive synchronization state acquisition and release, shared synchronization state acquisition and release, and timeout get synchronization state the core data structure and template method of Synchronizer.Synchronization Queue IntroductionSynchronizer relies on the internal synchronization queue (a FIFO bidirectional queue) to complete the management of the synchronization state, when the current thread gets the synchroniza
determine the number of times the current write lock was fetched * @author Fuyuwei * May 21, 2017 morning 11:05:05 * * @return * * Final int get
Writeholdcount () {return isheldexclusively () Exclusivecount (GetState ()): 0; }
Let's take a look at a caching example to illustrate the use of a read-write lock
public class Cache {
static map
The above hashmap is not thread safe, but we use read and write locks separately in get and put, which ensures thread safety, where write locks supp
Unsafe.java . As Unsafe.java for the specific implementation here is not discussed.CAS Typical applicationsjava.util.concurrent.atomicThe classes under the package are mostly implemented using CAS operations (eg. AtomicInteger.java , AtomicBoolean , AtomicLong ). The AtomicInteger.java implementation of these atomic classes is described in some detail below.2,aqs (AbstractQueuedSynchronizer) What is AqsFIFO queue + Atomic int (indicates state) Atom int:Atomicinteger The existence of this class
Countdownlatch, TXT file parsing here does not do the detailed code implementation.
Countdownlatch statement:The Countdownlatch constructor accepts the int parameter as its counter, and if it wants to wait for n points to complete, it passes N;
When calling Countdownlatch's Countdown method, the await method, where n reduces 1,countdownlatch, blocks the main thread until n is reduced to 0.
Countdownlatch Source Code AnalysisCountdownlatch is a custom Aqs synchronization
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.