# Class SessionPoolOptions.Builder (6.118.0)

6.118.0 (latest) 6.116.0 6.111.1 6.108.0 6.107.0 6.103.0 6.102.1 6.101.1 6.100.0 6.99.0 6.98.1 6.97.1 6.96.1 6.95.1 6.94.0 6.93.0 6.89.0 6.88.0 6.87.0 6.86.0 6.85.0 6.83.0 6.82.0 6.80.1 6.79.0 6.77.0 6.74.1 6.72.0 6.71.0 6.69.0 6.68.0 6.66.0 6.65.1 6.62.0 6.60.0 6.58.0 6.57.0 6.56.0 6.55.0 6.54.0 6.53.0 6.52.1 6.51.0 6.50.1 6.49.0 6.25.1 6.24.0 6.23.4 6.22.0 6.21.2 6.20.0 6.19.1 6.18.0 6.17.4 6.14.1

    public static class SessionPoolOptions.Builder

Builder for creating SessionPoolOptions.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> SessionPoolOptions.Builder

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Constructors

### Builder()

    public Builder()

## Methods

### build()

    public SessionPoolOptions build()

Build a SessionPoolOption object

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions` |   |

### setAcquireSessionTimeout(Duration acquireSessionTimeout) (deprecated)

    public SessionPoolOptions.Builder setAcquireSessionTimeout(Duration acquireSessionTimeout)

> [!WARNING]
> **Obsolete**
>
> *Use setAcquireSessionTimeoutDuration(Duration) instead*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is obsolete. Use [#setAcquireSessionTimeoutDuration(Duration)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder#com_google_cloud_spanner_SessionPoolOptions_Builder_setAcquireSessionTimeoutDuration_java_time_Duration_) instead.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `acquireSessionTimeout` | `org.threeten.bp.Duration` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setAcquireSessionTimeoutDuration(Duration acquireSessionTimeout) (deprecated)

    public SessionPoolOptions.Builder setAcquireSessionTimeoutDuration(Duration acquireSessionTimeout)

If greater than zero, we wait for said duration when no sessions are available in the
SessionPool. The default is a 60s timeout. Set the value to null to disable the timeout.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `acquireSessionTimeout` | `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setAutoDetectDialect(boolean autoDetectDialect)

    public SessionPoolOptions.Builder setAutoDetectDialect(boolean autoDetectDialect)

Sets whether the client should automatically execute a background query to detect the dialect
that is used by the database or not. Set this option to true if you do not know what the
dialect of the database will be.

Note that you can always call [DatabaseClient#getDialect()](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.DatabaseClient#com_google_cloud_spanner_DatabaseClient_getDialect__) to get the dialect of a
database regardless of this setting, but by setting this to true, the value will be
pre-populated and cached in the client.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `autoDetectDialect` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` Whether the client should automatically execute a background query to detect the dialect of the underlying database |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` | this builder for chaining |

### setBlockIfPoolExhausted() (deprecated)

    public SessionPoolOptions.Builder setBlockIfPoolExhausted()

If all sessions are in use and there is no more room for creating new sessions, block for a
session to become available. Default behavior is same.

By default the requests are blocked for 60s and will fail with a `SpannerException` with
error code `ResourceExhausted` if this timeout is exceeded. If you wish to block for a
different period use the option Builder#setAcquireSessionTimeoutDuration(Duration)
()}

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setExperimentalHost()

    public SessionPoolOptions.Builder setExperimentalHost()

> [!WARNING]
> **Internal Only**: This feature is not stable for application use.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setFailIfPoolExhausted() (deprecated)

    public SessionPoolOptions.Builder setFailIfPoolExhausted()

If all sessions are in use and `maxSessions` has been reached, fail the request by
throwing a [SpannerException](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SpannerException) with the error code `RESOURCE_EXHAUSTED`. Default
behavior is to block the request.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setKeepAliveIntervalMinutes(int intervalMinutes) (deprecated)

    public SessionPoolOptions.Builder setKeepAliveIntervalMinutes(int intervalMinutes)

How frequently to keep alive idle sessions. This should be less than 60 since an idle session
is automatically closed after 60 minutes. Sessions will be kept alive by sending a dummy
query "Select 1". Default value is 30 minutes.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `intervalMinutes` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setMaxIdleSessions(int maxIdleSessions) (deprecated)

    public SessionPoolOptions.Builder setMaxIdleSessions(int maxIdleSessions)

**Deprecated.** *set a higher value for [#setMinSessions(int)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder#com_google_cloud_spanner_SessionPoolOptions_Builder_setMinSessions_int_) instead of using this
configuration option. This option will be removed in a future release.*

Maximum number of idle sessions that this pool will maintain. Pool will close any sessions
beyond this but making sure to always have at least as many sessions as specified by [#setMinSessions](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder#com_google_cloud_spanner_SessionPoolOptions_Builder_setMinSessions_). To determine how many sessions are idle we look at maximum number of
sessions used concurrently over a window of time. Any sessions beyond that are idle. Defaults
to 0.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `maxIdleSessions` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setMaxSessions(int maxSessions) (deprecated)

    public SessionPoolOptions.Builder setMaxSessions(int maxSessions)

Maximum number of sessions that this pool will have. If current numbers of sessions in the
pool is less than this and they are all busy, then a new session will be created for any new
operation. If current number of in use sessions is same as this and a new request comes, pool
can either block or fail. Defaults to 400.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `maxSessions` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setMinSessions(int minSessions) (deprecated)

    public SessionPoolOptions.Builder setMinSessions(int minSessions)

Minimum number of sessions that this pool will always maintain. These will be created eagerly
in parallel. Defaults to 100.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `minSessions` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setRemoveInactiveSessionAfter(Duration duration) (deprecated)

    public SessionPoolOptions.Builder setRemoveInactiveSessionAfter(Duration duration)

> [!WARNING]
> **Obsolete**
>
> *Use setRemoveInactiveSessionAfterDuration(Duration) instead*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is obsolete. Use [#setRemoveInactiveSessionAfterDuration(Duration)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder#com_google_cloud_spanner_SessionPoolOptions_Builder_setRemoveInactiveSessionAfterDuration_java_time_Duration_)
instead.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `duration` | `org.threeten.bp.Duration` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setRemoveInactiveSessionAfterDuration(Duration duration) (deprecated)

    public SessionPoolOptions.Builder setRemoveInactiveSessionAfterDuration(Duration duration)

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `duration` | `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setTrackStackTraceOfSessionCheckout(boolean trackStackTraceOfSessionCheckout) (deprecated)

    public SessionPoolOptions.Builder setTrackStackTraceOfSessionCheckout(boolean trackStackTraceOfSessionCheckout)

Sets whether the session pool should capture the call stack trace when a session is checked
out of the pool. This will internally prepare a
com.google.cloud.spanner.SessionPool.LeakedSessionException that will only be thrown if the
session is actually leaked. This makes it easier to debug session leaks, as the stack trace
of the thread that checked out the session will be available in the exception.

Some monitoring tools might log these exceptions even though they are not thrown. This
option can be used to suppress the creation and logging of these exceptions.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `trackStackTraceOfSessionCheckout` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setWaitForMinSessions(Duration waitForMinSessions)

    public SessionPoolOptions.Builder setWaitForMinSessions(Duration waitForMinSessions)

> [!WARNING]
> **Obsolete**
>
> *Use setWaitForMinSessionsDuration(Duration) instead*
>
> This feature is stable for usage in this major version, but may be deprecated in a future release.

This method is obsolete. Use [#setWaitForMinSessionsDuration(Duration)](https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder#com_google_cloud_spanner_SessionPoolOptions_Builder_setWaitForMinSessionsDuration_java_time_Duration_) instead.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `waitForMinSessions` | `org.threeten.bp.Duration` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setWaitForMinSessionsDuration(Duration waitForMinSessions)

    public SessionPoolOptions.Builder setWaitForMinSessionsDuration(Duration waitForMinSessions)

If greater than zero, waits for the session pool to have at least SessionPoolOptions#minSessions before returning the database client to the caller. Note that
this check is only done during the session pool creation. This is usually done asynchronously
in order to provide the client back to the caller as soon as possible. We don't recommend
using this option unless you are executing benchmarks and want to guarantee the session pool
has min sessions in the pool before continuing.

Defaults to zero (initialization is done asynchronously).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `waitForMinSessions` | `https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |

### setWarnAndCloseIfInactiveTransactions() (deprecated)

    public SessionPoolOptions.Builder setWarnAndCloseIfInactiveTransactions()

If there are inactive transactions, release the resources consumed by such transactions. A
transaction is classified as inactive if it executes for more than a system defined duration.
The option would also produce necessary warning logs through which it can be debugged as to
what resources were released due to this option.

Use the option Builder#setWarnIfInactiveTransactions() if you only want to log
warnings about long-running transactions.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` | this builder for chaining |

### setWarnIfInactiveTransactions() (deprecated)

    public SessionPoolOptions.Builder setWarnIfInactiveTransactions()

If there are inactive transactions, log warning messages with the origin of such transactions
to aid debugging. A transaction is classified as inactive if it executes for more than a
system defined duration.

This option won't change the state of the transactions. It only generates warning logs
that can be used for debugging.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` | this builder for chaining |

### setWriteSessionsFraction(float writeSessionsFraction) (deprecated)

    public SessionPoolOptions.Builder setWriteSessionsFraction(float writeSessionsFraction)

**Deprecated.** *This configuration value is no longer in use. The session pool does not prepare
any sessions for read/write transactions. Instead, a transaction will automatically be
started by the first statement that is executed by a transaction by including a
BeginTransaction option with that statement.*

*This method may be removed in a future release.*

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `writeSessionsFraction` | `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.SessionPoolOptions.Builder` |   |