---
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 markdown="1">

[(constructor)(context, options)](./pooling.poolingservice._constructor_.md)


</td><td markdown="1">


</td><td markdown="1">

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 markdown="1">

[context](./pooling.poolingservice.context.md)


</td><td markdown="1">

`readonly`


</td><td markdown="1">

[Context](./context.context.md)


</td><td markdown="1">


</td></tr>
<tr><td markdown="1">

[pool](./pooling.poolingservice.pool.md)


</td><td markdown="1">

`readonly`


</td><td markdown="1">

Pool&lt;T&gt;


</td><td markdown="1">

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 markdown="1">

[acquire(requestCtx)](./pooling.poolingservice.acquire.md)


</td><td markdown="1">


</td><td markdown="1">

Acquire a new instance


</td></tr>
<tr><td markdown="1">

[destroy(resource)](./pooling.poolingservice.destroy.md)


</td><td markdown="1">


</td><td markdown="1">

Destroy a resource from the pool


</td></tr>
<tr><td markdown="1">

[release(resource)](./pooling.poolingservice.release.md)


</td><td markdown="1">


</td><td markdown="1">

Release the resource back to the pool.


</td></tr>
<tr><td markdown="1">

[run(task, requestCtx)](./pooling.poolingservice.run.md)


</td><td markdown="1">


</td><td markdown="1">

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 markdown="1">

[start()](./pooling.poolingservice.start.md)


</td><td markdown="1">


</td><td markdown="1">

Start the pool


</td></tr>
<tr><td markdown="1">

[stop()](./pooling.poolingservice.stop.md)


</td><td markdown="1">


</td><td markdown="1">

Stop the pool


</td></tr>
</tbody></table>


