Home> Java> javaTutorial> body text

How to combine soft references with queues in Java?

PHPz
Release: 2023-04-25 18:55:08
forward
1236 people have browsed it

Explanation

1. Soft references can be used in conjunction with reference queues. If the reference object referenced by the software is garbage collected. If an object has only soft references, the garbage collector will not reclaim it when the storage space is sufficient; if there is insufficient storage space, the storage of these objects will be reclaimed. As long as the garbage collector does not collect, the other party can use the program.

2. The JAVA virtual machine adds the software reference to the reference queue related to it.

Example

ReferenceQueue referenceQueue = new ReferenceQueue<>(); String str = new String("abc"); SoftReference softReference = new SoftReference<>(str, referenceQueue); str = null; // Notify GC System.gc(); System.out.println(softReference.get()); // abc Reference reference = referenceQueue.poll(); System.out.println(reference); //null
Copy after login

What are the basic data types of java

The basic data types of Java are divided into:

1. Integer type , a data type used to represent integers.

2. Floating point type, a data type used to represent decimals.

3. Character type. The keyword of character type is "char".

4. Boolean type is the basic data type that represents logical values.

The above is the detailed content of How to combine soft references with queues in Java?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!