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
ReferenceQueuereferenceQueue = 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 extends String> reference = referenceQueue.poll(); System.out.println(reference); //null
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!