{"id":15159354,"url":"https://github.com/andresilva/scala-pool","last_synced_at":"2025-05-02T12:32:19.047Z","repository":{"id":57732398,"uuid":"45080380","full_name":"andresilva/scala-pool","owner":"andresilva","description":"An object pool for Scala","archived":false,"fork":false,"pushed_at":"2019-11-23T19:55:59.000Z","size":1119,"stargazers_count":50,"open_issues_count":0,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-22T16:10:46.136Z","etag":null,"topics":["object-pool","pool","scala"],"latest_commit_sha":null,"homepage":null,"language":"Scala","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/andresilva.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}},"created_at":"2015-10-28T01:14:15.000Z","updated_at":"2024-04-16T13:29:43.000Z","dependencies_parsed_at":"2022-09-10T19:52:05.559Z","dependency_job_id":null,"html_url":"https://github.com/andresilva/scala-pool","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresilva%2Fscala-pool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresilva%2Fscala-pool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresilva%2Fscala-pool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andresilva%2Fscala-pool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andresilva","download_url":"https://codeload.github.com/andresilva/scala-pool/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252038263,"owners_count":21684662,"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":["object-pool","pool","scala"],"created_at":"2024-09-26T21:05:14.548Z","updated_at":"2025-05-02T12:32:14.025Z","avatar_url":"https://github.com/andresilva.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# scala-pool\n\n*scala-pool* is a Scala library for object pooling. The library provides an API and different pool\n implementations that allow:\n\n  - blocking/non-blocking object acquisition\n  - object invalidation\n  - capping the number of pooled objects\n  - creating new objects lazily, as needed\n  - health checking\n  - time-based pool eviction (idle instances)\n  - GC-based pool eviction (soft and weak references)\n  - efficient thread-safety\n\n* * *\n\n[![Build Status](https://img.shields.io/travis/andresilva/scala-pool/master.svg)](https://travis-ci.org/andresilva/scala-pool)\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.andrebeat/scala-pool_2.13.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.andrebeat/scala-pool_2.13)\n[![Coverage](https://img.shields.io/coveralls/andresilva/scala-pool/master.svg)](https://coveralls.io/github/andresilva/scala-pool)\n[![License](https://img.shields.io/dub/l/vibe-d.svg)](https://raw.githubusercontent.com/andresilva/scala-pool/master/LICENSE)\n[![Scaladoc](http://javadoc-badge.appspot.com/io.github.andrebeat/scala-pool_2.13.svg?label=scaladoc)](http://javadoc-badge.appspot.com/io.github.andrebeat/scala-pool_2.13/io/github/andrebeat/pool/index.html)\n[![Scaladoc](https://img.shields.io/badge/scaladoc-latest-brightgreen.svg)](https://andresilva.github.io/scala-pool)\n\n## Installation\n\nscala-pool is currently available for Scala 2.13, 2.12, and 2.11, the latest version is `0.4.3`.\n\nTo use it in an existing SBT project, add the following dependency to your `build.sbt`:\n\n```scala\nlibraryDependencies += \"io.github.andrebeat\" %% \"scala-pool\" % \"0.4.3\"\n```\n\nThe latest snapshot version is also available:\n\n```scala\nlibraryDependencies += \"io.github.andrebeat\" %% \"scala-pool\" % \"0.5.0-SNAPSHOT\"\n```\n\nIt might be necessary to add the Sonatype OSS Snapshot resolver:\n\n```scala\nresolvers += Resolver.sonatypeRepo(\"snapshots\")\n```\n\nCurrently, the library has no external dependencies apart from the Java and Scala standard\nlibraries.\n\n### JDK7 support\n\nThis library relies on features only available in Java 8 (`java.util.concurrent.atomic.LongAdder`),\nthe versions published on Sonatype are compiled with JDK 8. This library provides support for JVM 7\nif it is compiled with JDK 7 (only for Scala 2.11). If you need to use this library on JVM 7 then\nyou should compile and package it yourself.\n\n## Usage\n\nThe basic usage of the pool is shown below:\n\n```scala\nimport io.github.andrebeat.pool._\n\n// Creating a `Pool[Object]` with a capacity of 2 instances\nval pool = Pool(2, () =\u003e new Object)\n\n// Acquiring a lease on an object from the pool (blocking if none available)\nval lease = pool.acquire()\n\n// Using the lease\nlease { o =\u003e\n  println(o)\n}\n\n// The object is returned to the pool at this point\n```\n\nAll of the different pool features are exposed in the `Pool` companion object `apply` method:\n\n```scala\nPool(\n  capacity: Int,                // the maximum capacity of the pool\n  factory: () =\u003e A,             // the function used to create new objects in the pool\n  referenceType: ReferenceType, // the reference type of objects in the pool\n  maxIdleTime: Duration,        // the maximum amount of the time that objects are allowed\n                                //   to idle in the pool before being evicted\n  reset: A =\u003e Unit,             // the function used to reset objects in the pool\n                                //   (called when leasing an object from the pool)\n  dispose: A =\u003e Unit,           // the function used to destroy an object from the pool\n  healthCheck: A =\u003e Boolean)    // the predicate used to test whether an object is\n                                //   healthy and should be used, or destroyed otherwise\n```\n\nIt is also possible to get a value from a lease and release it (or invalidate) manually.\n\n```scala\nimport io.github.andrebeat.pool._\n\n// Creating a `Pool[Object]` with a capacity of 2 instances\nval pool = Pool(2, () =\u003e new Object)\n\n// Getting the value from the lease\nval obj = lease.get()\n\n// There are currently no objects on the pool\npool.size\n// res0: Int = 0\n\n// But its capacity is 2 (objects are created lazily)\npool.capacity\n// res1: Int = 2\n\n// There's 1 live object\npool.live\n// res2: Int = 1\n\n// And its currently leased\npool.leased\n// res3: Int = 1\n\n// Releasing our lease back to the pool\nlease.release\n\n// Its now in the pool waiting to be reused\npool.size\n// res4: Int = 1\n\n// Closes this pool, properly disposing of each pooled object and \n// releasing any resources associated with the pool\npool.close()\n```\n\nThe API is documented in depth in the [Scaladoc](https://andresilva.github.io/scala-pool/).\n\n## License\n\nscala-pool is licensed under the [MIT](http://opensource.org/licenses/MIT) license. See `LICENSE`\nfor details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandresilva%2Fscala-pool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandresilva%2Fscala-pool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandresilva%2Fscala-pool/lists"}