---
lang: en
title: 'API docs: pooling.poolingservice'
keywords: LoopBack 4.0, LoopBack 4, Node.js, TypeScript, OpenAPI
sidebar: lb4_sidebar
editurl: https://github.com/loopbackio/loopback-next/tree/master/extensions/pooling
permalink: /doc/en/lb4/apidocs.pooling.poolingservice.html
---

<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@loopback/pooling](./pooling.md) &gt; [PoolingService](./pooling.poolingservice.md)

## PoolingService class

A singleton service to maintain a pool of resources. This pool service can be bound to different keys to represent multiple pools. Each binding is a singleton so that the state stays the same for injections into multiple instances for other artifacts.

**Signature:**

```typescript
export declare class PoolingService<T> implements LifeCycleObserver 
```
**Implements:** [LifeCycleObserver](./core.lifecycleobserver.md)

## Remarks

Some resources can be expensive to create/start. For example, a datasource has overhead to connect to the database. There will be performance penalty to use `TRANSIENT` scope and creates a new instance per request. But it is not feasible to be a singleton for some use cases, for example, each request may have different security contexts.

The pool service observes life cycle events to start and stop.

## Constructors

<table><thead><tr><th>

Constructor


</th><th>

Modifiers


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[(constructor)(context, options)](./pooling.poolingservice._constructor_.md)


</td><td>


</td><td>

Constructs a new instance of the `PoolingService` class


</td></tr>
</tbody></table>

## Properties

<table><thead><tr><th>

Property


</th><th>

Modifiers


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[context](./pooling.poolingservice.context.md)


</td><td>

`readonly`


</td><td>

[Context](./context.context.md)


</td><td>


</td></tr>
<tr><td>

[pool](./pooling.poolingservice.pool.md)


</td><td>

`readonly`


</td><td>

Pool&lt;T&gt;


</td><td>

The resource pool


</td></tr>
</tbody></table>

## Methods

<table><thead><tr><th>

Method


</th><th>

Modifiers


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

[acquire(requestCtx)](./pooling.poolingservice.acquire.md)


</td><td>


</td><td>

Acquire a new instance


</td></tr>
<tr><td>

[destroy(resource)](./pooling.poolingservice.destroy.md)


</td><td>


</td><td>

Destroy a resource from the pool


</td></tr>
<tr><td>

[release(resource)](./pooling.poolingservice.release.md)


</td><td>


</td><td>

Release the resource back to the pool.


</td></tr>
<tr><td>

[run(task, requestCtx)](./pooling.poolingservice.run.md)


</td><td>


</td><td>

Run the task with an acquired resource from the pool. If task is completed successfully, the resource is returned to the pool. Otherwise, the resource is destroyed.


</td></tr>
<tr><td>

[start()](./pooling.poolingservice.start.md)


</td><td>


</td><td>

Start the pool


</td></tr>
<tr><td>

[stop()](./pooling.poolingservice.stop.md)


</td><td>


</td><td>

Stop the pool


</td></tr>
</tbody></table>


