In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the strong, soft, virtual and weak citation of JAVA". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the strong, soft, virtual and weak citation of JAVA?"
Strong citation
As long as there is a reference, the target object will not be garbage disposed of by GC
Soft reference
SoftReference wrapper is used. When there is insufficient memory, GC will recycle the corresponding soft reference object.
GC will be specially handled (the call GC,HotSpot JVM shown is stop other threads, and GC; as soon as possible will not GC immediately)
Virtual reference
PhantomReference is used in conjunction with queues (JVM is in use, and GC's underlying implementation is in use)
Help reclaim out-of-heap memory, such as external buffers that netty supports access. JVM points directly to the reference to this buffer, and individual threads scan the wrapped queue for recycling.
Weak reference
If the WeakReference is between a strong reference and a soft reference, the object will be recycled after a GC.
Example 1: ThreadLocal is an embodiment of weak references, and the thread's local Map is inherited from WeakReference
The ThreadLocal Set method sets the current object to the Map of the current thread. Key is the ThreadLocal object and value is the target object.
The following figure is detailed:
Example 2: transaction @ Transaction
Different DAO calling methods, how to ensure access to the same database connection to ensure transaction consistency
When the method that starts execution is executed, the acquired database connection object is put into the ThreadLocalMap of the current thread
The next execution method, which is fetched directly from the ThreadLocalMap of the current thread, guarantees the same database connection to ensure the transaction.
Thank you for your reading, the above is the content of "what is the strong, soft, virtual and weak citation of JAVA". After the study of this article, I believe you have a deeper understanding of what the strong, soft, virtual and weak citation of JAVA is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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: 226
*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.