Stay organized with collections
Save and categorize content based on your preferences.
ReferenceQueue
open class ReferenceQueue<T : Any!>
Reference queues, to which registered reference objects are appended by the garbage collector after the appropriate reachability changes are detected.
Summary
Public constructors |
Constructs a new reference-object queue.
|
Public methods |
open Reference<out T>! |
Polls this queue to see if a reference object is available.
|
open Reference<out T>! |
Removes the next reference object in this queue, blocking until one becomes available.
|
open Reference<out T>! |
Removes the next reference object in this queue, blocking until either one becomes available or the given timeout period expires.
|
Public constructors
ReferenceQueue
ReferenceQueue()
Constructs a new reference-object queue.
Public methods
poll
open fun poll(): Reference<out T>!
Polls this queue to see if a reference object is available. If one is available without further delay then it is removed from the queue and returned. Otherwise this method immediately returns null.
Return |
Reference<out T>! |
A reference object, if one was immediately available, otherwise null |
remove
open fun remove(): Reference<out T>!
Removes the next reference object in this queue, blocking until one becomes available.
Return |
Reference<out T>! |
A reference object, blocking until one becomes available |
Exceptions |
java.lang.InterruptedException |
If the wait is interrupted |
remove
open fun remove(timeout: Long): Reference<out T>!
Removes the next reference object in this queue, blocking until either one becomes available or the given timeout period expires.
This method does not offer real-time guarantees: It schedules the timeout as if by invoking the Object.wait(long)
method.
Parameters |
timeout |
Long: If positive, block for up to timeout milliseconds while waiting for a reference to be added to this queue. If zero, block indefinitely. |
Return |
Reference<out T>! |
A reference object, if one was available within the specified timeout period, otherwise null |
Exceptions |
java.lang.IllegalArgumentException |
If the value of the timeout argument is negative |
java.lang.InterruptedException |
If the timeout wait is interrupted |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# ReferenceQueue\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)\n\nReferenceQueue\n==============\n\n```\nopen class ReferenceQueue\u003cT : Any!\u003e\n```\n\n|---|-----------------------------------|\n| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) ||\n| ↳ | [java.lang.ref.ReferenceQueue](#) |\n\nReference queues, to which registered reference objects are appended by the garbage collector after the appropriate reachability changes are detected.\n\nSummary\n-------\n\n| Public constructors ||\n|----------------------------------------------------------------------------------|---|\n| [ReferenceQueue](#ReferenceQueue())`()` Constructs a new reference-object queue. |\n\n| Public methods ||\n|-----------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| open [Reference](/reference/kotlin/java/lang/ref/Reference)\\\u003cout T\\\u003e! | [poll](#poll())`()` Polls this queue to see if a reference object is available. |\n| open [Reference](/reference/kotlin/java/lang/ref/Reference)\\\u003cout T\\\u003e! | [remove](#remove())`()` Removes the next reference object in this queue, blocking until one becomes available. |\n| open [Reference](/reference/kotlin/java/lang/ref/Reference)\\\u003cout T\\\u003e! | [remove](#remove(kotlin.Long))`(`timeout:` `[Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html)`)` Removes the next reference object in this queue, blocking until either one becomes available or the given timeout period expires. |\n\nPublic constructors\n-------------------\n\n### ReferenceQueue\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nReferenceQueue()\n```\n\nConstructs a new reference-object queue.\n\nPublic methods\n--------------\n\n### poll\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun poll(): Reference\u003cout T\u003e!\n```\n\nPolls this queue to see if a reference object is available. If one is available without further delay then it is removed from the queue and returned. Otherwise this method immediately returns null.\n\n| Return ||\n|------------------------------------------------------------------|------------------------------------------------------------------------|\n| [Reference](/reference/kotlin/java/lang/ref/Reference)\u003cout` `T\u003e! | A reference object, if one was immediately available, otherwise `null` |\n\n### remove\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun remove(): Reference\u003cout T\u003e!\n```\n\nRemoves the next reference object in this queue, blocking until one becomes available.\n\n| Return ||\n|------------------------------------------------------------------|----------------------------------------------------------|\n| [Reference](/reference/kotlin/java/lang/ref/Reference)\u003cout` `T\u003e! | A reference object, blocking until one becomes available |\n\n| Exceptions ||\n|----------------------------------|----------------------------|\n| `java.lang.InterruptedException` | If the wait is interrupted |\n\n### remove\n\nAdded in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels) \n\n```\nopen fun remove(timeout: Long): Reference\u003cout T\u003e!\n```\n\nRemoves the next reference object in this queue, blocking until either one becomes available or the given timeout period expires.\n\nThis method does not offer real-time guarantees: It schedules the timeout as if by invoking the [Object.wait(long)](../Object.html#wait(kotlin.Long)) method.\n\n| Parameters ||\n|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `timeout` | [Long](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-long/index.html): If positive, block for up to `timeout` milliseconds while waiting for a reference to be added to this queue. If zero, block indefinitely. |\n\n| Return ||\n|------------------------------------------------------------------|------------------------------------------------------------------------------------------------|\n| [Reference](/reference/kotlin/java/lang/ref/Reference)\u003cout` `T\u003e! | A reference object, if one was available within the specified timeout period, otherwise `null` |\n\n| Exceptions ||\n|--------------------------------------|--------------------------------------------------|\n| `java.lang.IllegalArgumentException` | If the value of the timeout argument is negative |\n| `java.lang.InterruptedException` | If the timeout wait is interrupted |"]]