In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the relevant contents of Java citations?" in the operation of actual cases, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
I. definition of reference
Before JDK 1.2, the definition of a reference in Java was traditional: if the value stored in data of type reference represents the starting address of another piece of memory, that piece of memory represents a reference.
Second, the question
When describing a class of objects that can be kept in memory when there is enough memory space, and can be discarded if memory space is still very tight after garbage collection. At this time, the citation is too narrow. So after JDK 1.2, the concept of Java heap reference has been extended.
III. Classification of citations
Recycling timing strong reference Strong Reference similar to Object obj = new Object () as long as the strong reference exists, the garbage collector will never recycle the referenced object soft reference Soft Reference describes some useful but not necessary objects that will be listed in the scope of recycling for a second collection before a memory overflow exception is about to occur in the system. If there is not enough memory in this collection, a memory overflow exception weak reference Weak Reference is thrown to describe non-essential objects, which is weaker than soft references. Objects associated with weak references can only survive until the next garbage collection occurs when the garbage collector works, regardless of whether the current memory is sufficient or not, the object virtual references associated with paper cups weak references Phantom Reference, also known as ghost references or phantom references, the weakest kind of reference relationship. Whether an object has a false reference or not will not affect its survival time at all, and it is impossible to obtain an object instance through virtual reference. The purpose of setting a vest associated with a virtual reference for an object is to receive a system notification when the object is reclaimed by the collector. 4. Application scenario
1. Strong citation
The most commonly used, with the most application scenarios, everywhere
two。 Soft reference
Only when OOM is about to occur, it will be actively recycled and applied to some applications with large memory restrictions to avoid OOM.
3. Weak reference
Both young gc and full gc recycle weakly referenced objects. When you want to reference an object, but the object has its own life cycle, you do not want to intervene in the life cycle of the object, you are using weak references.
4. Virtual reference
It can be detected during collection that the virtual reference is mainly used to track the activity of the object being reclaimed by the garbage collector.
5. Source code package org.pdool.ref;import java.lang.ref.Reference;import java.lang.ref.ReferenceQueue;import java.lang.ref.WeakReference;import java.util.LinkedList;public class ReferenceTest {private static ReferenceQueue rq = new ReferenceQueue (); public static void checkQueue () {Reference
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.