Reentrantlock is a new class that JDK5 joins, and its usage is similar to synchronized. It requires the programmer to manually add lock and unlock code.than the benefits of synchronized. It adds two methods:L provides Trylock () when the method is called. If the lock is held by another object, it returns false.L also one is the fair lock. At the time of constructing the Reentrantlock. It has a person of type Boolean parameter. This parameter is descri
(this) {
For (int i=0;i10;i++)
System.out.println (Thread.CurrentThread (). GetName () +":" +i);
}
}
}
To view bytecode directives:2.ReentrantLockSince Reentrantlock is a set of mutexes provided under the Java.util.concurrent package, there are some advanced features compared to the Synchronized,reentrantlock class, with the following 3 main items:1. Waiting can be interrupted, the thread holding the lock is not released for a long time, the waiting thread can choose to gi
blocked and cannot be executed. Application Scenarios
Semaphore can be used for traffic control, especially for limited public resource applications, such as database connections. If there is a requirement to read tens of thousands of files of data, because are IO-intensive tasks, we can start dozens of threads concurrent read, but if you read the memory, you also need to store in the database, and the number of database connections only 10, At this point we have to control only 10 threads at t
main performance in the following two aspects: (1) The manual task and the scheduling task share a queue "hive", while the queue "hive" resource allocation is mainly based on the resource consumption of scheduling tasks allocated, so that the random submission of manual tasks and scheduling tasks together, it may affect the execution speed of the original scheduling task And can not choose the appropriate scheduling strategy according to the respective characteristics of the two tasks (e.g. FI
and traverse a two-way linked list
6. Searching elements in a two-way linked list
VII. Concept of circular linked list
8. merge two linked list instances
IX. Video Information Management System
Expand your thinking, and finally go to the end to see (• Fair fair Fair • Fair) fair
, there are always only a few people in life who want to make friends. But for a variety of reasons, most people do not know how minority people understand the behavior of most of them. Just now, Xiaoqiang said that his "real friend" never "snatched" his toys, but "changed ". Note these two words.
Here we will not discuss the so-called "mind calculation ". It is true that some people have a deep City, at least more advanced than others. They can achieve their own goals even if they do not think
Salary tracking for many college graduates in Guangzhou this year
So far, the 2006 job fair for college graduates has been held for nearly 20. Many people are wondering how the salary of college graduates this year is? This version specially sent reporters to many job fairs for interviews. The information they brought back is: although many enterprises have pressed the price of college students, the salary offered by enterprises is not small distance
speed. If the real-time clock is over 20 seconds, the virtual clock is only 5 seconds. If the CPU is allocated in a fair way, the 5 seconds of the virtual clock can be used as the benchmark.
Assume that the virtual clock of the ready queue is fair_clock, and the waiting time of the process is stored in wait_runtime. fair_clock indicates the time that the process needs to run under a completely fair conditi
want to make friends. But for a variety of reasons, most people do not know how minority people understand the behavior of most of them. Just now, Xiaoqiang said that his "real friend" never "snatched" his toys, but "changed ". Note these two words.
Here we will not discuss the so-called "mind calculation ". It is true that some people have a deep City, at least more advanced than others. They can achieve their own goals even if they do not think of anything else. Here we will only discuss the
a Semaphore with the given number of licenses and unfair fair settings.The signal lamp created by the first constructor is random and has no sequence. For example, in the preceding example, a signal lamp is released after one of the first three threads is completed, the remaining two threads will run with a random thread getting the signal lamp.Second:[Java]Semaphore (int permits, boolean fair) // create a
the two cannot actually run in parallel, which is particularly different from the linkedblockingqueue, and according to the principle of implementation, The arrayblockingqueue can be fully split-lock, enabling full parallel operation of both producer and consumer operations. Doug Lea did not do this, perhaps because Arrayblockingqueue's data write and fetch operations are lightweight enough to introduce an independent locking mechanism that, in addition to adding additional complexity to the co
, which means that the two cannot actually run in parallel, which is particularly different from the linkedblockingqueue, and according to the principle of implementation, The arrayblockingqueue can be fully split-lock, enabling full parallel operation of both producer and consumer operations. Doug Lea did not do this, perhaps because Arrayblockingqueue's data write and fetch operations are lightweight enough to introduce an independent locking mechanism that, in addition to adding additional co
Sorting rule ResolutionFirst, the principle of search sortingThe overall goal of the AliExpress search is to help our buyers quickly find the goods they want and to have a better purchasing experience, and the goal of the search ranking is to give priority to the best sellers of goods and services to our buyers, who can bring buyers the best purchasing experience, Whose goods will be sorted by the front.In the sequencing process, we will always adhere to the principle of fairness, for all seller
Chapter 8 ArrayBlockingQueue source code parsing and arraydeque source code parsing
Note: You need to use ReentrantLock before reading this article or during the reading process. For details, see chapter 5 ReentrantLock source code parsing 1-obtain unfair lock and fair lock () chapter 6 ReentrantLock source code parsing 2 -- release Lock unlock () Chapter 7 ReentrantLock Summary
1. For ArrayBlockingQueue, master the following points:
Create
Join (a
Java. util. concurrent package source code reading 17 semaphores Semaphore and semaphores semaphore
Anyone who has learned about the operating system knows the Semaphore. In the java. util. concurrent package, there is also a Semaphore implementation: Semaphore.
From the perspective of code implementation, semaphores and locks are similar. They can be regarded as a limited shared lock, that is, shared locks that can only be used by a limited number of threads.
Because there is a count, the Sema
[Switch] Analysis of SynchronousQueue, LinkedBlockingQueue, ArrayBlockingQueue, and linkedblockingqueue
Address: http://blog.csdn.net/mn11201117/article/details/8671497SynchronousQueue
SynchronousQueue is unbounded and a non-buffered waiting Queue. However, due to its own characteristics, after an element is added, you must wait for other threads to remove it before adding it; synchronousQueue can be considered as a blocking queue with a cache value of 1, but the isEmpty () method always returns
and the consumer, which means that the two cannot actually run in parallel, which is particularly different from the linkedblockingqueue, and according to the principle of implementation, The arrayblockingqueue can be fully split-lock, enabling full parallel operation of both producer and consumer operations. Doug Lea did not do this, perhaps because Arrayblockingqueue's data write and fetch operations are lightweight enough to introduce an independent locking mechanism that, in addition to add
operations. Doug Lea did not do this, perhaps because Arrayblockingqueue's data write and fetch operations are lightweight enough to introduce an independent locking mechanism that, in addition to adding additional complexity to the code, is not a good performance benefit. One notable difference between Arrayblockingqueue and Linkedblockingqueue is that the former does not produce or destroy any additional object instances when inserting or deleting elements, while the latter generates an addit
ReentrantLock: ReentrantLock Is A reentrant mutex lock. It is also called an exclusive lock ". As the name suggests, the ReentrantLock can only be held by one thread lock at the same time point. reentrant means that the ReentrantLock can be obtained multiple times by a single thread. ReentrantLock is divided into "fair lock" and "unfair lock ". Their difference lies in the fairness of the lock acquisition mechanism. The "Lock" is used to protect compe
internal lock is a fair lock, and an unfair lock is used by Default.2. linkedblockingqueueA linked list-based blocking queue, similar to arraylistblockingqueue, maintains a data buffer queue (which is made up of a list of lists), and when the producer puts a data into the queue, the queue fetches the data from the producer and caches it inside the Queue. The producer returns immediately; the producer queue is blocked until the queue buffer reaches th
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.