In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
The main content of this article is to explain "what is the principle of LinkedBlockingQueue". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the principle of LinkedBlockingQueue"?
LinkedBlockingQueue
Node representation that makes up a linked list
Static class Node
< E >{
E item
Node
< E >Next
Node (E x) {
Item = x
}
}
Linked list attribute
Private final int capacity
Private final AtomicInteger count = new AtomicInteger ()
Transient Node
< E >Head
Private transient Node
< E >Last
Private final ReentrantLock takeLock = new ReentrantLock ()
Private final ReentrantLock putLock = new ReentrantLock ()
Private final Condition notEmpty = takeLock.newCondition ()
Private final Condition notFull = putLock.newCondition ()
The methods used are
Private void signalNotEmpty ()
Private void signalNotFull ()
Private void enqueue (Node
< E >Node)
Private E dequeue ()
Double lock
/ / encapsulate the fixed locking order in the method to ensure that all locks are locked in the same order. Void fullyLock () {putLock.lock (); takeLock.lock ();} / / encapsulates the fixed release lock order in the method, ensuring that all releases of the two locks are in the same order. Void fullyUnlock () {takeLock.unlock (); putLock.unlock ();}
Construction method
Public LinkedBlockingQueue (int capacity) {
If (capacity (null))
}
Public LinkedBlockingQueue (Collection
< ? extends E >c)
Public int size ()
Public int remainingCapacity ()
Enter
Public void put (E e) throws InterruptedException
Public boolean offer (E e, long timeout, TimeUnit unit)
Public boolean offer (E e)
Out
Public E take () throws InterruptedException
Public E poll (long timeout, TimeUnit unit) throws InterruptedException
Public E poll ()
/ * * take it from the head * /
Public E peek ()
Public boolean remove (Object o)
Public boolean contains (Object o)
Public Object [] toArray ()
Public
< T >T [] toArray (T [] a)
.
At this point, I believe you have a deeper understanding of "what is the principle of LinkedBlockingQueue". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.