使用的是jboss7.1.1, jndi的配置在$JBOSS_HOME/standalone/configuration/standalone.xml中進行配置。配置jndi時有很多參數,解釋下用到的一些參數:
jndi-name
The JNDI name under which the Datasource should be bound.
datasource需要綁定的JNDI名稱。
use-java-context
Boolean value indicating whether the jndi-name should be prefixed with java:. This prefix causes the Datasource to only be accessible from within the JBoss Enterprise Platform virtual machine. Defaults toTRUE.
布爾值表明是否在JNDI名稱前加上前綴 "java:",默認值為
"TRUE",也就是添加前綴"java:"
user-name
The user name used to create the connection to the datasource.
創建鏈接連接數據源的時候使用的用戶名
password
The password used to create the connection to the datasource.
創建鏈接連接數據源的時候使用的密碼
connection-url
The JDBC driver connection URL string
連接數據源的URL字符串
min-pool-size
The minimum number of connections maintained in the pool. Unless is TRUE, the pool remains empty until the first use, at which point the pool is filled to the . When the pool size drops below the due to idle timeouts, the pool is refilled to the . Defaults to 0.
數據庫連接池保留的最小連接數。除非參數值為"TRUE",否則連接池在第一次使用前都將保持空連接數,當第一次使用后,數據庫連接池會自動將連接數填滿為所配置的最小連接數。當因為閑置而超時時,連接池將刪除連接至最小連接數以下,但之后連接池會重新將連接數填為所配置的最小連接數。默認值為
0.
max-pool-size
The maximum number of connections allowed in the pool. Defaults to 20.
數據庫連接池允許的最大連接數。默認值為
20
prefill
Whether to attempt to prefill the connection pool to the minimum number of connections. Only supporting pools (OnePool) support this feature. A warning is logged if the pool does not support prefilling. Defaults to TRUE.
是否在一開始的時候就嘗試將連接池的連接數預先增加為配置的最小連接個數;否則在第一次獲取連接時才啟動創建最小連接個數。只有支持的連接池支持這個特性。如果連接池不支持預先填滿,那么會有一個警告被打印。默認值為
"TRUE"。
blocking-timeout-millis
The length of time, in milliseconds, to wait for a connection to become available when all the connections are checked out. Defaults to 30000, which is 30 seconds.
當所有的連接都被占用后,從連接池中等待一個連接變為可用的時間;如果超過該時間,則超時。單位是毫秒。默認是30000毫秒,也就是30秒。
idle-timeout-minutes
The maximum time, in minutes, before an idle connection is closed. A value of 0 disables timeout. Defaults to 15 minutes.
一個連接最大的空閑時間,超過這個時間,連接就會被關閉。如果值設置為0則禁用這個功能,默認為15分鍾。后台程序會定時清理過度空閑的連接來節省數據庫的連接資源。
valid-connection-checker
A class that checks whether a connection is valid using a vendor-specific mechanism.
使用一個廠商的機制來檢查一個連接是否有效。
check-valid-connection-sql
An SQL statement that is executed before the connection is checked out from the pool to make sure it is still valid. If the SQL statement fails, the connection is closed and a new one is created.
在連接從連接池中被占用前會執行該SQL,來確保連接仍然有效。如果SQL執行失敗,那么連接會被關閉並且同時會創建一個新的連接。
exception-sorter
A class that parses vendor-specific messages to determine whether SQL errors are fatal, and destroys the connection if so. If empty, no errors are treated as fatal.
默認情況下,jboss不會對無效的連接進行銷毀,如果我們需要對異常列表中的連接進行銷毀,則需要在設置該配置。該類解析每個廠商不同的應答來決定SQL執行的錯誤是否是致命的,如果是的話就會銷毀該連接。如果為空的話,那么任何錯誤都不會被認為是致命的。