WebSphere数据源中的连接被意外关闭案例
来源:互联网 发布:数控铣床编程简单100例 编辑:程序博客网 时间:2024/06/16 09:04
频繁创建连接的现象
前阵子维护反馈说,oracle数据库每秒创建连接数过高,而主要来源来自于WebSphere集群所在的主机。
按理说,使用连接池的应用,连接是不会很频繁的。追溯一下所在主机的程序,发现可疑对象是一个使用jdbc轮子的应用。
就是自己写了一套代码封装了jdbc操作,虽然连接是从数据源中获取的。
但是,单纯看代码,的确没发现有什么问题,该关闭的地方也关闭,不存在泄露的情况。再说,这种现象也不是泄露的表现。
另外,由于生产上的数据库连接串,开发人员是没有的,所以生成都是通过jndi的方式来处理的,不存在盗链的代码。
不过,我们还是在日志里边发现一些问题。在SystemOut的日志里边,频繁出现类似下面的异常信息:
[12-2-27 9:01:29:262 GMT+08:00] 00000038 MCWrapper E J2CA0081E: 尝试对资源 ecareDB 的 ManagedConnection WSRdbManagedConnectionImpl@23f823f8 执行方法 cleanup 时,方法 cleanup 失败。捕获的异常:com.ibm.ws.exception.WsException: DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: Cannot call 'cleanup' on a ManagedConnection while it is still in a transaction..
异常的来源,居然是连接的close方法。
为什么close会失败
在WebSphere的资料上没有找到相关的描述,但是我在ibatis的文档上找到了相关的描述(ibatis developer guide的12-13页):
The element also allows an optional attribute commitRequired that can be true or
false. Normally iBATIS will not commit transactions unless an insert, update, or delete operation has been
performed. This is true even if you explicitly call the commitTransaction() method. This behavior
creates problems in some cases. If you want iBATIS to always commit transactions, even if no insert,
update, or delete operation has been performed, then set the value of the commitRequired attribute to true.
Examples of where this attribute is useful include:
If you call a stored procedures that updates data as well as returning rows. In that case you would
call the procedure with the queryForList() operation – so iBATIS would not normally commit the
transaction. But then the updates would be rolled back.In a WebSphere environment when you are using connection pooling and you use the JNDI
and the JDBC or JTA transaction manager. WebSphere requires all transactions on
pooled connections to be committed or the connection will not be returned to the pool.
Note that the commitRequired attribute has no effect when using the EXTERNAL transaction manager.
结论及对策
从上面的描述上看到,WebSphere环境的连接是需要提交事务的,否则会被意外关闭。
并且,如果选择ibatis的事务管理机制,就应该设置commitRequired属性,要么就应该使用spring的事务解决方案。
我们尝试给查询语句增加commit操作,果然异常信息不再出现,并且数据库连接数也大幅度减少了。
看来,在生产系统中还是应该优先考虑成熟的解决方案,不要随便造轮子。
- WebSphere数据源中的连接被意外关闭案例
- WCF 基础连接已经关闭:连接被意外关闭
- WCF 基础连接已经关闭: 连接被意外关闭。
- .net wcf 返回DataTable 调用 ”基础连接已经关闭: 连接被意外关闭“
- WCF-003:关于 WCF 基础连接已经关闭 连接被意外关闭-序列化问题
- 错误解决: WCF 基础连接已经关闭: 连接被意外关闭
- httpWebRequest请求错误,基础连接已经关闭: 连接被意外关闭
- Websphere 命令行配置DB2数据源连接池
- WebSphere中的Oracle数据源设置------JSP和Oracle数据库的连接
- C# WebRequest 基础连接已关闭 连接意外关闭
- Websphere Applicaiton Server集群中的数据源配置
- WCF-005:关于 WCF 基础连接已经关闭 连接被意外关闭-不是使用父类指向子类问题
- WebSphere使用数据源连接数据库的事务问题
- 使用SOAP协议修改websphere数据源的密码,测试连接
- websphere 使用JNDI连接数据源的配置文件编写
- mybatis连接多个数据源成功案例
- WebSphere中的Oracle数据源设置------JSP和Oracle数据
- websphere配置oracle数据源
- Duilib 创建自定义控件
- Log4J使用详解(整理)
- [机械键盘]Filco87 奶酪绿 FKBN87MRL/ECW2 开箱
- 依赖注入
- Http、TCP/IP、UDP
- WebSphere数据源中的连接被意外关闭案例
- Codeforces 673D Bear and Two Paths【贪心】
- Java中有关Null的注意事项
- 【译】Android 7.0 for Developers
- 性能优化:Trove集合库
- 在linux下安装JDK
- 2.12.1 求数列的和
- vue自定义日期组件
- 搭建ftp图片服务器,通过Nginx来显示