Home  >  Article  >  Java  >  How to use java weak references in combination with queues

How to use java weak references in combination with queues

WBOY
WBOYforward
2023-05-24 15:43:061191browse

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);
    }
}

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete