Home > Java > javaTutorial > body text

How to use java weak references in combination with queues

WBOY
Release: 2023-05-24 15:43:06
forward
1226 people have browsed it

1. Instructions for use

Weak references can be used in conjunction with the reference queue. The weak reference object will be garbage collected, and the Java virtual machine will add the weak reference to the reference queue related to it. middle.

2. Examples

public class GCTarget {
    // 对象的ID
    public String id;
 
    // 占用内存空间
    byte[] buffer = new byte[1024];
 
    public GCTarget(String id) {
        this.id = id;
    }
 
    protected void finalize() throws Throwable {
        // 执行垃圾回收时打印显示对象ID
        System.out.println("Finalizing GCTarget, id is : " + id);
    }
}
Copy after login

What are the commonly used java frameworks

1.SpringMVC, Spring Web MVC is a Java-based implementation of the Web A lightweight web framework based on the request-driven MVC design pattern.

2.Shiro, Apache Shiro is a security framework for Java.

3.Mybatis, MyBatis is an excellent persistence layer framework that supports ordinary SQL queries, stored procedures and advanced mapping.

4.Dubbo, Dubbo is a distributed service framework.

5.Maven, Maven is a project management and build automation tool.

6.RabbitMQ, RabbitMQ is a high-concurrency and high-reliability AMQP message queue server implemented in Erlang.

7.Ehcache, EhCache is a pure Java in-process caching framework.

The above is the detailed content of How to use java weak references in combination with queues. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template