a synchronous lock, which is a built-in lock, or a lock is monitored, and a built-in lock is obtained by means of a synchronous method or block of code, that is, using the Synchronized keyword2). Display lockThe advanced locks provided by the JDK, such as lock, condition, etc., are mainly used for the functions of the built-in lock not easy to implement3. Some features of the lock1). Can be re-enteredJava Threads Compute locks on a per-thread basis, and in the same thread, you can enter the syn
Prior to Java5.0, only synchronized (built-in lock) and volatile. The display lock Reentrantlock is introduced after Java5.0.
Reentrantlock OverviewThe Reentrantlock is a reentrant lock, which differs from the built-in lock, which needs to display the lock and unlock for each use, and provides more advanced features: Fair lock, timed lock, conditional lock, polling lock, interruptible lock. Can effectively avoid the deadlock of the active problem
33.1.1.1Telnet 33.1.1.1 80View commandsShow IP access-listsShow Class-mapShow Policy-mapShow Policy-map Interface S0/14. Queue technology (congestion management)Queue technology is applied to the direction of the interface, and an interface can use only one queue technology.There is a software queue and a hardware queue on the router's interface. The packet enters the soft queue first, and then the packet is dispatched into the hardware queue using the queue technology, and the hardware queue a
require immediate response and execution. such as video playback software or aircraft flight control system, it is obvious that such programs can not tolerate long delays in scheduling, light impact on the film screening effect, heavy machine destroyed human death.Linux uses different scheduling strategies based on the different classifications of the process. For real-time processes, a FIFO or Round Robin scheduling strategy is used. For normal processes, it is necessary to differentiate betwe
Reentrantlock Introduction
Reentrantlock is a reentrant mutex, also known as an "exclusive lock."
As the name suggests, Reentrantlock locks can only be held by a single thread lock at one point in time, and reentrant means that reentrantlock locks can be acquired multiple times by individual threads.
Reentrantlock is divided into "fair lock" and "unjust lock". Their differences are reflected in the fairness of the mechanism for acquiring locks. "Lo
)//returns the string that identifies this semaphore, and the status of the semaphore. String toString ()//A license is obtained from the semaphore only if there is one available license for this semaphore at the time of invocation. BooleanTryacquire ()//These licenses are obtained from this semaphore only when there is a given number of licenses in this semaphore at the time of invocation. BooleanTryacquire (intpermits)//if all licenses are available for this semaphore within a given wait time,
indicating the status is 1, put the current thread into the waiting queue and block itself(After being awakenedLockMethod, and return to 1stStep to start again).
Note: wakeup does not indicate that the thread can run immediately, but that the thread is in the ready state and can run.
General process of thread release lock
1. The thread releasing the lock sets the value of the status variable from 1 to 0, and wakes upFirst NodeThe thread that releases the lock returns from the unlock method and
Now it is very popular to buy train tickets for the Spring Festival, and many sellers are eager to start marketing, such as using plug-ins to grab tickets.
This article will discuss what is "fairness ".
If the agent purchases tickets fairly, is it fair to look for leading backdoors and use scalpers to purchase tickets? Are there any essential differences in their nature?
First remark: using advanced technologies to purchase tickets is a manifestation
Concurrentlinkedqueue, Synchronousqueue (fair mode) and Linkedblockingqueue. And LinkedTransferQueue is better, because it not only synthesizes the functions of these classes, but also provides a more efficient implementation.Joe Bowbeer offers a paper by William Scherer, Doug Lea, and Michael Scott, which shows the linkedtransferqueue algorithm in this paper, and the performance test results show that it is better than Java 5 of those classes (trans
0. PrefaceUnlike synchronized, lock is written entirely in Java and is not implemented by the JVM at the level of Java.In the Java.util.concurrent.locks package there are many implementation classes of lock, commonly used are reentrantlock, readwritelock (Implementation class Reentrantreadwritelock), Its realization all relies on the Java.util.concurrent.AbstractQueuedSynchronizer class, realizes the idea to be similar, therefore we take the Reentrantlock as the explanation entry point.1. Reentr
thread more flexible. using synchronized is equivalent to having only one single condition object in the entire lock object, all of which are registered on the body of one of its objects, when the thread starts Notifyall (), Need to notify all the waiting threads, there is no option, there will be a lot of efficiency problems. NBSP;46, condition implementation wait/notification: The Wait () method in the object class is equivalent to the await () method in the Condition class; the Notify (
This section is mainly about the implementation of read-write locks.As mentioned in the previous section, Readwritelock appears to have two locks: readlock/writelock. If it's really two locks, how do they affect each other?In fact, the realization of lock in Reentrantreadwritelock is done by Java.util.concurrent.locks.ReentrantReadWriteLock.Sync. This class looks familiar, in fact it is a subclass of Aqs, a similar structure that exists in Countdownlatch, Reentrantlock, and semaphore. It also ha
interrupted = false;for (;;) {Final Node p = node.predecessor ();if (p = = head tryacquire (ARG)) {Sethead (node);P.next = null; Help GCreturn interrupted;}if (Shouldparkafterfailedacquire (p, node) Parkandcheckinterrupt ())interrupted = true;}} catch (RuntimeException ex) {Cancelacquire (node);Throw ex;}}
In Sethead , the predecessor node of the header is emptied and the thread of the head node is emptied for a better GC to prevent memory leaks.
private void Sethead (node node) {Hea
current object.
The following is an implementation of a blocking queue:
public class blockqueue{
private List = new ArrayList ();
Public synchronized Object POPs () throws interruptedexception{while
(List.size () ==0) {
this.wait ();
}
if (List.size () >0) {return
list.remove (0);
} else{return
null;
}
Public synchronized object (object obj) {
list.add (obj);
This.notify ();
}
Synchronized with Wait (), notify () should be the basic skills that Java developer
With the popularity of MapReduce, the Open-source implementation of Hadoop has become increasingly popular. In a Hadoop system, it is important to have a component that is the scheduler that allocates the idle resources in the system to the job in a certain policy. In Hadoop, a scheduler is a pluggable module that allows users to design dispatchers according to their actual application requirements. There are three types of schedulers common in Hadoop, respectively:
(Note: The Hadoop scheduler
thread that acquires the lock, increments the synchronization state and returns True, indicating that the synchronization state was successful.In the case of a fair lock, you also need to determine whether the current node in the synchronization queue has a precursor node, and if so, wait for the predecessor thread to acquire the lock and release it before continuing to acquire the lock.Fair lock and non-fair
O (1) scheduler, which helps to get rid of the limitations of the child's previous scheduler through a static time slice algorithm and a running queue for each processor. However, its time-sensitive process is inherently congenital, so-called time-sensitive processes, refers to the existence of a large number of user interaction processes, such as desktop programs, it needs to respond quickly to customer operations.In the Linux 2.6 kernel, the "complete Fai
.SynchronizedSynchronized in the compilation, will be in the synchronization block before and after the formation of Monitorenter and monitorexit this two-byte code instruction. When executing the monitorenter instruction, the first attempt is to acquire an object lock. If the object is not locked, or when the front-thread already has the object lock, the lock calculator plus 1, the corresponding, in the execution of the monitorexit instruction will be the lock calculator minus 1, when the calcu
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service