使用 wsadmin 工具更改连接池设置
您可以使用 wsadmin 脚本编制工具来更改连接池设置。
关于此任务
wsadmin 工具运行脚本。可使用 wsadmin 工具来管理 WebSphere® Application Server 安装和配置、应用程序部署及服务器运行时操作。该产品支持 Jacl 和 Jython 脚本编制语言。要了解有关 wsadmin 工具的更多信息,请参阅“启动 wsadmin 脚本编制客户机”主题。
要使用 wsadmin 工具来更改连接池设置:
过程
示例:使用 wsadmin 工具更改连接池设置。
通过使用 wsadmin AdminControl 对象,可以脚本编制对连接池设置所作的更改。
wsadmin 工具仅运行使用 Jacl 和 Jython 语言的脚本。必须启动 wsadmin 脚本客户机才能执行任何脚本编制任务。有关更多信息,请参阅“启动 wsadmin 脚本编制客户机”主题。
有关 AdminControl 脚本编制对象的更多信息,请参阅“使用 AdminControl 对象来进行脚本化管理”主题。
当池活动时,可以在任何时间更改连接超时。如果更改连接超时值,那么正在等待的所有连接请求的连接超时都会更改为新值减去连接已等待的时间,如果没有可用连接,那么请求会返回至等待状态。
例如,如果连接超时被更改为 300 秒,且连接请求已等待 100 秒,那么在没有连接可用时,那么此连接请求会等待 200 多秒。
$AdminControl getAttribute $objectname connectionTimeout
$AdminControl setAttribute $objectname connectionTimeout 200
有关此设置的更多信息,请参阅主题“连接池设置”。。
可以在任何时间更改最大连接数,除非启用了粘滞连接支持。
如果启用了粘滞连接支持,那么尝试更改最大连接数。如果尝试失败,那么会发生 IllegalState 异常。请参阅主题“连接池高级设置”,以了解更多信息。
如果没有启用粘滞连接支持,那么将最大连接数更改为新的值。如果新的值大于当前值,那么连接数增加到新的值并且通知任何等待的请求。如果新的值小于当前值并且使用了时效超时或收集时间,那么根据池活动情况,将连接数减小成新的值。如果没有使用时效超时或收集时间,那么将不会自动尝试减少连接总数。要将连接数手动地减小到新的最大连接数,使用 Mbean 函数 purgePoolContents。
$AdminControl getAttribute $objectname maxConnections
$AdminControl setAttribute $objectname maxConnections 200
有关此设置的更多信息,请参阅主题“连接池设置”。
可以在任何时间更改最小连接数。
$AdminControl getAttribute $objectname minConnections
$AdminControl setAttribute $objectname minConnections 200
有关此设置的更多信息,请参阅主题“连接池设置”。
可以在任何时间更改收集时间。在下一个时间间隔将收集时间时间间隔更改为新的值。
$AdminControl getAttribute $objectname reapTime
$AdminControl setAttribute $objectname reapTime 30
未使用超时可以在任何时间更改未使用的超时。
$AdminControl getAttribute $objectname unusedTimeout
$AdminControl setAttribute $objectname unusedTimeout 900
有关此设置的更多信息,请参阅主题“连接池设置”。
可以在任何时间更改时效超时。
$AdminControl getAttribute $objectname agedTimeout
$AdminControl setAttribute $objectname agedTimeout 900
有关此设置的更多信息,请参阅主题“连接池设置”。
可以在任何时间更改清除策略。
$AdminControl getAttribute $objectname purgePolicy
$AdminControl setAttribute $objectname purgePolicy "Failing Connection Only"
有关此设置的更多信息,请参阅主题“连接池设置”。
如果 surgeThreshold 大于 -1,并且 surgeCreationInterval 大于 0,那么启动波动连接支持。可以在任何时间更改波动保护属性。
$AdminControl getAttribute $objectname surgeCreationInterval
$AdminControl setAttribute $objectname surgeCreationInterval 30
$AdminControl getAttribute $objectname surgeThreshold
$AdminControl setAttribute $objectname surgeThreshold 15
有关此设置的更多信息,请参阅主题“连接池设置”。
尝试更改 stuckTime、stuckTimerTime 或 stuckThreshold 属性。如果尝试失败,那么会发生 IllegalState 异常。此请求期间,池不能有任何活动的请求或活动的连接。对于要启动粘滞连接支持,三个粘滞属性值都必须大于 0,并且最大连接数值必须大于 0。
如果连接池是粘滞的,那么您无法更改粘滞属性或最大连接属性。如果是粘滞的,那么存在活动连接。
$AdminControl getAttribute $objectname stuckTime
$AdminControl setAttribute $objectname stuckTime 30
$AdminControl getAttribute $objectname stuckTimerTime
$AdminControl setAttribute $objectname stuckTimerTime 15
$AdminControl getAttribute $objectname stuckThreshold
$AdminControl setAttribute $objectname stuckThreshold 10
有关此设置的更多信息,请参阅主题“连接池高级设置”。
如果 testConnection 属性设置为 true,并且时间间隔大于 0,那么测试连接支持将启动。可以在任何时间更改测试连接属性。
$AdminControl getAttribute $objectname testConnection
$AdminControl setAttribute $objectname testConnection 30
$AdminControl getAttribute $objectname testConnectionInterval
$AdminControl setAttribute $objectname testConnectionInterval 15
有关此设置的更多信息,请参阅主题“测试连接服务”。
$AdminControl invoke $objectname freePoolDistributionTableSize
$AdminControl invoke $objectname numberOfFreePoolPartitions
$AdminControl invoke $objectname numberOfSharedPoolPartitions
$AdminControl invoke $objectname gatherPoolStatisticalData
$AdminControl invoke $objectname enablePoolStatisticalData
有关此设置的更多信息,请参阅主题“连接池设置”。
可以在任何时间更改显示池操作。
$AdminControl invoke $objectname showAllPoolContents
$AdminControl invoke $objectname showPoolContents
$AdminControl invoke $objectname showAllocationHandleList
可以在任何时间更改 PurgePool。
$AdminControl invoke $objectname purgePoolContents normal
$AdminControl invoke $objectname purgePoolContents immediate
- 现有的正在进行的事务继续工作。
- 接受共享连接请求。
- 可用连接被清除并断开。
- 正在使用的连接(事务中的连接)在返回至连接池后被清除并断开。
- 对进行 purgePoolContents 调用之前获取的任何连接发出的 close() 调用会同步完成(它们会等待 JDBC 驱动程序返回,然后继续)。
- 接受对新连接的请求(并非现有旧连接的句柄)。
- 不允许在进行 purgePoolContents 调用前获取的任何连接上启动新事务。而是抛出 StaleConnectionException。
- 不允许在进行 purgePoolContents 调用前获取的任何连接上分发新句柄。而是抛出 StaleConnectionException。
- 现有的正在进行的事务继续工作,但被清除连接上的任何新活动会导致 StaleConnectionException 或 XAER_FAIL 异常。
- 对进行 purgePoolContents() 调用之前获取的任何连接发出的 close() 调用会异步完成(无等待时间)。
- 接受对新连接的请求(并非现有旧连接的句柄)。
- 连接数会立即减少。这可能会导致应用程序服务器中的总连接数与数据库中的总连接数暂时不同步。
- 对进行 purgePoolContents() 调用之前获取的任何连接发出的 close() 调用会异步完成(无等待时间)
- 接受对新连接的请求(并非现有旧连接的句柄)。
- 连接数会立即减少。这可能会导致应用程序服务器中的总连接数与后端资源中的总连接数暂时不同步。
可以在任何时间更改 pause 和 resume。
$AdminControl invoke $objectname pause
$AdminControl invoke $objectname resume
Wsadmin 命令用于访问连接工厂和数据源 MBean。MBean 可以检索或更新连接工厂或数据源的属性。
要获取 J2C 连接工厂或数据源 Mbean 对象名的列表,在 wsadmin 命令行使用下列某个管理控制命令:
$AdminControl queryNames *:type=J2CConnectionFactory,*
$AdminControl queryNames *:type=DataSource,*
从数据源查询输出的示例:
wsadmin>$AdminControl queryNames *:type=DataSource,*
"WebSphere:name=Default Datasource,process=server1,platform=dynamicproxy,node=
system1Node01,JDBCProvider=Derby JDBC Provider,j2eeType=JDBCDataSource,J2EESe
rver=server1,Server=server1,version=6.0.0.0,type=DataSource,mbeanIdentifier=cell
s/system1Node01Cell/nodes/system1Node01/servers/server1/resources.xml#DataSource
_1094760149902,JDBCResource=Derby JDBC Provider,cell=system1Node01Cell"
您可以通过使用 J2C 连接工厂或数据源 MBean 对象名来访问 MBean。名称在 webSphere:name= 表达式后面。在以下示例中,对于第一个设置,在变量名上设置缺省数据源名。对于第二个设置,在变量 objectName 上设置对象名。
使用缺省数据源的示例:
- wsadmin>set name [list Default Datasource]
Default Datasource
- wsadmin>set objectName [$AdminControl queryNames *:name=$name,*]
"WebSphere:name=Default Datasource,process=server1,platform=dynamicproxy,node=
system1Node01,JDBCProvider=Derby JDBC Provider,j2eeType=JDBCDataSource,J2EESe
rver=server1,Server=server1,version=6.0.0.0,type=DataSource,mbeanIdentifier=cell
s/system1Node01Cell/nodes/system1Node01/servers/server1/resources.xml#DataSource
_1094760149902,JDBCResource=Derby JDBC Provider,cell=system1Node01Cell"
现在,您可以使用 objectName 来获取关于此 Mbean 的可用属性和操作的帮助。
$Help attributes $objectName
$Help operations $objectName
要获取或设置属性,或者要使用操作,使用以下某个命令:
$AdminControl getAttribute $objectName "attribute name"
$AdminControl setAttribute $objectName "attribute name" value
$AdminControl invoke $objectName "operation"
属性和操作示例:
Get and set an attribute maxConnections. If you get no value, a null value, or
a java.lang.IllegalStateException, the connection factory or data source for this
MBean has not been created. The connection factory or data source is created at first
JNDI lookup. For this example, the Default DataSource must be used before get,
set and invoke will work.
wsadmin>$AdminControl getAttribute $objectName maxConnections
10
wsadmin>$AdminControl setAttribute $objectName maxConnections 20
wsadmin>$AdminControl getAttribute $objectName maxConnections
20
Using invoke
wsadmin>$AdminControl invoke $objectName showPoolContents
PoolManager name:DefaultDatasource
PoolManager object:746354514
Total number of connections: 3 (max/min 20/1, reap/unused/aged 180/1800/0,
connectiontimeout/purge 1800/EntirePool)
(testConnection/inteval false/0, stuck timer/time
/threshold 0/0/0, surge time/connections 0/-1)
Shared Connection information (shared partitions 200)
No shared connections
Free Connection information (free distribution table/partitions 5/1)
(2)(0)MCWrapper id 5c6af75b Managed connection WSRdbManagedConnectionImpl@4b5
a775b State:STATE_ACTIVE_FREE
(2)(0)MCWrapper id 3394375a Managed connection WSRdbManagedConnectionImpl@328
5f75a State:STATE_ACTIVE_FREE
(2)(0)MCWrapper id 4795b75a Managed connection WSRdbManagedConnectionImpl@46a
4b75a State:STATE_ACTIVE_FREE
Total number of connections in free pool: 3
UnShared Connection information
No unshared connections