{"id":19674007,"url":"https://github.com/robaho/closablequeue","last_synced_at":"2025-05-05T22:42:51.622Z","repository":{"id":250173163,"uuid":"833693386","full_name":"robaho/closablequeue","owner":"robaho","description":"a Java FIFO blocking queue with \"close\" semantics. designed for virtual threads.","archived":false,"fork":false,"pushed_at":"2025-01-07T17:54:33.000Z","size":107,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-07T18:54:39.620Z","etag":null,"topics":["blocking-queue","closable","queue","virtual","virtual-threads"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robaho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-25T14:54:10.000Z","updated_at":"2025-01-07T17:54:36.000Z","dependencies_parsed_at":"2024-12-17T23:28:28.276Z","dependency_job_id":null,"html_url":"https://github.com/robaho/closablequeue","commit_stats":null,"previous_names":["robaho/closablequeue"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robaho%2Fclosablequeue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robaho%2Fclosablequeue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robaho%2Fclosablequeue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robaho%2Fclosablequeue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robaho","download_url":"https://codeload.github.com/robaho/closablequeue/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233292643,"owners_count":18654092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blocking-queue","closable","queue","virtual","virtual-threads"],"created_at":"2024-11-11T17:16:57.790Z","updated_at":"2025-01-10T04:13:04.937Z","avatar_url":"https://github.com/robaho.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a unbounded FIFO queue that offers \"close\" semantics.\n\nIt is designed to be used with try-with-resources and ephemeral virtual threads to ensure proper clean-up of threads.\n\nIt only supports some of the Queue interface methods, so it is not a drop-in replacement, but most of ommitted methods are probably not useful in a high-volume VT environment.\n\nTODO: use read/write lock to improve the concurrency between readers and writers when not using SingleConsumerQueue\n\nTODO: possibly implement the rest of the BlockingQueue interface methods to make it a drop-in replacement.\n\n## usage\n\nThe code will most likely be structured similar to:\n\n```java\ntry(var queue=new ClosableQueue\u003cT\u003e()) {\n   Thread.startVirtualThread(newConsumer(queue));\n  ... put() items into queue from source/generation ...\n}\n```\n\nand the consumer:\n\n```java\nfor(T e, e=queue.take();) {\n  ... do something with e ...\n}\n```\n\nor possibly more efficiently:\n\n```java\nArrayList\u003cT\u003e elements = new ArrayList();\nwhile(queue.drainToBlocking(elements)\u003e0) {\n  ... for each e in elements do ...\n  elements.clear();\n}\n```\n\nThe `take()` in consumer will throw an `QueueClosedException` (subclass of `IllegalStateException`) if the queue is closed and all elements from the queue have been processed (i.e. queue is empty and closed).\n\nMultiple producers and consumers are supported. Once the queue is closed, any `put()` related methods will fail with a `QueueClosedException`.\n\nSee [ClosableQueue](lib/src/main/java/robaho/queue/ClosableQueue.java)\n\n## single consumer queue\n\nThe library also includes a highly efficient closable queue specifically designed for the case of a single active reader - which is expected to be most of time when using ephemeral virtual thread queues.\n\n```java\ntry(var queue=new SingleConsumerQueue\u003cT\u003e()) {\n   Thread.startVirtualThread(newConsumer(queue));\n  ... put() items into queue from source/generation ...\n}\n```\n\nSee [SingleConsumerQueue](lib/src/main/java/robaho/queue/SingleConsumerQueue.java)\n\n## performance\n\nThere are jmh benchmarks that test against the standard concurrent queues:\n\n```\nBenchmark                                                    Mode  Cnt     Score     Error  Units\nClosableQueueBenchmark.testClosableQueue                     avgt    9   142.820 ±  11.575  ns/op\nClosableQueueBenchmark.testSingleConsumerQueue               avgt    9    71.104 ±   2.867  ns/op\nClosableQueueBenchmark.testLinkedBlockingQueue               avgt    9   168.452 ±  11.434  ns/op\nClosableQueueBenchmark.testLinkedTransferQueue               avgt    9    64.612 ±   0.924  ns/op\nClosableQueueBenchmark.testLinkedTransferQueueUsingTransfer  avgt    9  1687.000 ± 496.429  ns/op\n```\n\n## maven\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003eio.github.robaho\u003c/groupId\u003e\n  \u003cartifactId\u003eclosablequeue\u003c/artifactId\u003e\n  \u003cversion\u003e1.0.8\u003c/version\u003e\n\u003c/dependency\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobaho%2Fclosablequeue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobaho%2Fclosablequeue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobaho%2Fclosablequeue/lists"}