Journal for Developers

Reference Queues | Java

0 58

Notice: Undefined index: rate in /home/content/p3pnexwpnas11_data03/84/3795084/html/wp-content/themes/publisher/includes/functions.php on line 5360
1 min read

Reference Queues as the name suggests is a data structure that is used to enqueue the reference objects, such as, WeakReference, SoftReference, and PhantomReference.

Read More: Java Reference Objects and Garbage Collection

Based upon the type of reference object, the exact point when the object will be enqueued varies. The enqueued object also depends on whether the ReferenceQueue object is provided at the time of the creation of the reference object.

Example code for better understanding of the ReferenceQueue and Reference Object creation.

StringBuilder sbObject = new StringBuilder();

ReferenceQueue<StringBuilder> refQueue = new ReferenceQueue<>();

PhantomReference<StringBuilder> sbPhantomRef = new PhantomReference<>(sbObject, refQueue);

sbObject = null

Apart from PhantomReference, it is not mandatory or even useful to provide one.



Subscribe to our Journal

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!