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 > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "Netty distributed high-performance tool class heterothread recovery object analysis". In daily operation, I believe that many people have doubts about the problem of recycling object analysis under Netty distributed high-performance tool class heterothread. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Netty distributed high-performance tool class heterothreading recovery object analysis". Next, please follow the editor to study!
Reclaim objects from different threads
It is the logic of object recycling when creating objects and recycling objects are not in the same thread.
As we briefly explained in the previous section, the non-thread recycling object will not be placed in the stack of the current thread, but in a WeakOrderQueue data structure. Review our previous figure:
8-6-1
For the relevant logic, we follow the source code:
Start with the entry method of the recycled object, the recycle method of DefualtHandle:
Public void recycle (Object object) {if (object! = value) {throw new IllegalArgumentException ("object does not belong to handle");} stack.push (this);}
This part is no stranger to us, following the push method:
Void push (DefaultHandle item) {Thread currentThread = Thread.currentThread (); if (thread = = currentThread) {pushNow (item);} else {pushLater (item, currentThread);}}
As analyzed in the previous section, the same thread will go to pushNow, and the specific logic is also analyzed.
If you are not in the same thread, you will go to the pushLater method and pass in the handle object and the current thread object
Follow to private void pushLater (DefaultHandle item, Thread thread) {Map, WeakOrderQueue > > DELAYED_RECYCLED = new FastThreadLocal, WeakOrderQueue > initialValue () {return new WeakHashMap [] elements = new DefaultHandle [link _ CAPACITY]; private int readIndex; private Link next;} in the pushLater method
Each time a Link is created, an array of type DefaultHandle is created to hold DefaultHandle objects. The default size is 16.
ReadIndex is a read pointer, which we will analyze in a later section.
The next node points to the next link
Go back to the constructor of WeakOrderQueue:
Owner is a wrapper around the forward thread, representing the current thread
Next, in a synchronization block, insert the currently created WeakOrderQueue into the first WeakOrderQueue that stack points to, that is, the head attribute of stack, and point to the WeakOrderQueue we created, as shown in the figure
8-6-3
If thread 2 creates a WeakOrderQueue associated with stack, the head node of the stack points to thread 2 to create the WeakOrderQueue
If thread 3 then creates a WeakOrderQueue associated with stack, the head node of stack points to the WeakOrderQueue of the newly created thread 3
Then the WeakOrderQueue of thread 3 points to the WeakOrderQueue of thread 2
That is, no matter which thread creates a WeakOrderQueue associated with the same stack, it is inserted into the header of the WeakOrderQueue list that stack points to.
This allows stack and other threads to release the object's container WeakOrderQueue for binding
Back to the pushLater method private void pushLater (DefaultHandle item, Thread thread) {Map
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.