const class sql::SqlConnPool
sys::Obj sql::SqlConnPool
SqlConnPool manages a pool of reusable SQL connections
- autoCommit
-
Bool autoCommitautoCommit sets the autoCommit mode used by connections in the pool. Applied when a connection is opened and restored when it is released, so a callback cannot leave the mode changed for the next borrower. Changing it at runtime takes effect per connection on its next release.
If auto-commit is true then each statement is executed and committed as an individual transaction. Otherwise statements are grouped into transaction which must be closed via SqlConn.commit or SqlConn.rollback.
- checkoutTimeout
-
const Duration checkoutTimeout := 30secMax time to block waiting for a connection to become available in the pool before raising TimeoutErr. Opening a new connection is bounded separately by
connectTimeout. - close
-
Void close()Close all connections, stop houseKeeping, and raise exception on any new executes
- connectTimeout
-
const Duration? connectTimeout := 10secMax time to wait when opening a new connection before raising TimeoutErr, or null to wait as long as the driver allows, which may be forever if the server stalls the handshake. Enforced by the driver via the 'connectTimeout' and 'socketTimeout' connection properties. JDBC resolves it in whole seconds; anything under a second is rounded up to one second.
- execute
-
Allocate a SQL connection inside the given callback. If a connection cannot be acquired before checkoutTimeout elapses then a TimeoutErr is raised. Do not close the connection inside the callback.
- houseKeepingFreq
-
const Duration houseKeepingFreq := 30secHow often the pool runs houseKeeping: close connections idle past
linger, retire connections older thanmaxLifetime, ping idle connections due a keepAlive, and warn about connections held pastleakWarn. Scheduled by the pool; callers do not drive it. - isClosed
-
Bool isClosed()Return if close has been called.
- keepAliveFreq
-
const Duration? keepAliveFreq := 2minHow long an idle connection may sit before houseKeeping pings it, or null to never ping idle connections. A failed ping evicts the connection. Must be less than
lingerto have any effect. A ping does not count as a use and does not deferlinger. - leakTrace
-
const Bool leakTrace := falseCapture a stack trace at every checkout and include it in the
leakWarnwarning. Costs a stack fill per checkout, so it is off by default. - leakWarn
-
const Duration leakWarn := 2minTime a connection may be held by an execute callback before a warning is logged that it may be stuck or leaked. The warning is logged once per checkout.
- linger
-
const Duration linger := 5minTime to linger an idle connection before closing it.
- log
-
const Log log := Log.get("sqlPool")Logger
- make
-
new make(|This|? f)It-block construtor
- maxConns
-
const Int maxConns := 10Max number of simultaneous connections to allow before blocking threads
- maxLifetime
-
const Duration maxLifetime := 30minMax lifetime of a connection before it is retired, regardless of how recently it was used. This protects against database and network infrastructure that kills long lived connections. Connections in use are never retired until released back to the pool.
- onClose
-
protected virtual Void onClose(SqlConn c)onClose is invoked just before a connection is closed by the pool.
- onOpen
-
protected virtual Void onOpen(SqlConn c)onOpen is invoked just after a connection is opened by the pool.
- password
-
const Str? passwordConnection password
- queryTimeout
-
const Duration? queryTimeout := 1minDefault timeout applied to every statement created on connections from this pool, or null for no timeout. Restored when a connection is released, so a callback that changes the connection's timeout cannot leave it changed for the next borrower. Applies per execution, so a batch must complete within it. JDBC resolves it in whole seconds; anything under a second is rounded up to one second.
- stats
-
Snapshot of the pool's gauges and cumulative counters:
- total: Connections the pool holds, including slots still being opened
- active: Connections currently checked out. A slot reserved for a connection that is still opening counts here.
- idle: Connections available for checkout. A connection held by a keepAlive ping counts here.
- waiting: Threads blocked waiting for a connection
- maxConns: SqlConnPool.maxConns
- checkouts: Connections handed to an execute callback
- checkoutTimeouts: Checkouts that gave up after SqlConnPool.checkoutTimeout
- opened: Connections opened against the database
- retired: Connections closed for age: idle past SqlConnPool.linger, or older than SqlConnPool.maxLifetime
- evicted: Connections closed as broken: failed validation on checkout, failed after an execute callback raised, or failed a keepAlive ping
- leakWarnings: Warnings logged for connections held past SqlConnPool.leakWarn
- uri
-
const Str uriConnection URI
- username
-
const Str? usernameConnection username
- validateAfterIdle
-
const Duration? validateAfterIdle := 500msPing a connection on checkout only if it has been idle at least this long, or null to never ping on checkout. The ping costs a database round trip. Governs checkout only: a connection is always validated after an execute callback raises.
- validationTimeout
-
const Duration validationTimeout := 3secMax time a liveness ping may take before the connection is treated as broken. JDBC resolves this in whole seconds; anything under a second is rounded up to one second.