日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

Apache-DBCP数据库连接池解读

發(fā)布時(shí)間:2025/3/21 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Apache-DBCP数据库连接池解读 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

  • 概述
  • 配置項(xiàng)說明
    • 基本配置項(xiàng)
      • username
      • password
      • url
      • driverClassname
      • connectionProperties
    • 事務(wù)相關(guān)配置項(xiàng)
    • 數(shù)據(jù)源鏈接數(shù)量配置項(xiàng)
    • 連接健康情況維護(hù)和檢查
    • 緩存語句配置項(xiàng)
    • 連接泄露回收配置項(xiàng)

概述

官網(wǎng): https://commons.apache.org/proper/commons-dbcp/index.html

commons-dbcp2包依賴于commons-pool2包中的代碼來提供底層對(duì)象池機(jī)制。


DBCP現(xiàn)在有三種不同的版本來支持不同版本的JDBC。如下所示

  • DBCP 2 compiles and runs under Java 7 only (JDBC 4.1)

  • DBCP 1.4 compiles and runs under Java 6 only (JDBC 4)

  • DBCP 1.3 compiles and runs under Java 1.4-5 only (JDBC 3)

由Java 7運(yùn)行的應(yīng)用程序應(yīng)使用DBCP 2。

由Java 6運(yùn)行的應(yīng)用程序應(yīng)使用DBCP 1.4。

在Java 1.4下運(yùn)行時(shí)應(yīng)使用DBCP 1.3。


DBCP 2基于Commons Pool 2,與DBCP 1.x相比,提供了更高的性能,JMX支持以及眾多其他新功能。 由于DBCP 2.x與DBCP 1.x不是兼容的,所以升級(jí)到2.x的用戶應(yīng)該知道Java包名稱已經(jīng)改變,以及Maven坐標(biāo)。 用戶還應(yīng)該注意,一些配置選項(xiàng)(例如maxActive to maxTotal)已被重命名.


配置項(xiàng)說明

基本配置項(xiàng)

username

連接的用戶名,通過驅(qū)動(dòng)創(chuàng)建我們需要的連接

password

連接的密碼,通過驅(qū)動(dòng)創(chuàng)建我們所需要的連接.

url

連接的路徑,通過驅(qū)動(dòng)創(chuàng)建我們所需要的連接.

driverClassname

要使用的JDBC驅(qū)動(dòng)程序的完全限定的Java類名稱

connectionProperties

JDBC驅(qū)動(dòng)建立連接時(shí)附帶的連接屬性屬性的格式必須為這樣:[屬性名=property;]
注意:”username” 與 “password” 兩個(gè)屬性會(huì)被明確地傳遞,因此這里不需要包含他們。

比如:

connectionProperties=useUnicode=true;characterEncoding=utf8

事務(wù)相關(guān)配置項(xiàng)


數(shù)據(jù)源鏈接數(shù)量配置項(xiàng)

注意: If maxIdle is set too low on heavily loaded systems it is possible you will see connections being closed and almost immediately new connections being opened. This is a result of the active threads momentarily closing connections faster than they are opening them, causing the number of idle connections to rise above maxIdle. The best value for maxIdle for heavily loaded system will vary but the default is a good starting point.


連接健康情況維護(hù)和檢查



緩存語句配置項(xiàng)

This component has also the ability to pool PreparedStatements. When enabled a statement pool will be created for each Connection and PreparedStatements created by one of the following methods will be pooled:

public PreparedStatement prepareStatement(String sql)public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)

NOTE - Make sure your connection has some resources left for the other statements. Pooling PreparedStatements may keep their cursors open in the database, causing a connection to run out of cursors, especially if maxOpenPreparedStatements is left at the default (unlimited) and an application opens a large number of different PreparedStatements per connection. To avoid this problem, maxOpenPreparedStatements should be set to a value less than the maximum number of cursors that can be open on a Connection.


連接泄露回收配置項(xiàng)

If you have enabled removeAbandonedOnMaintenance or removeAbandonedOnBorrow then it is possible that a connection is reclaimed by the pool because it is considered to be abandoned. This mechanism is triggered when (getNumIdle() < 2) and (getNumActive() > getMaxTotal() - 3) and removeAbandonedOnBorrow is true; or after eviction finishes and removeAbandonedOnMaintenance is true. For example, maxTotal=20 and 18 active connections and 1 idle connection would trigger removeAbandonedOnBorrow, but only the active connections that aren’t used for more then “removeAbandonedTimeout” seconds are removed (default 300 sec). Traversing a resultset doesn’t count as being used. Creating a Statement, PreparedStatement or CallableStatement or using one of these to execute a query (using one of the execute methods) resets the lastUsed property of the parent connection.

總結(jié)

以上是生活随笔為你收集整理的Apache-DBCP数据库连接池解读的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。