本站首页    管理页面    写新日志    退出


«October 2025»
1234
567891011
12131415161718
19202122232425
262728293031


公告

戒除浮躁,读好书,交益友


我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:邢红瑞的blog
日志总数:523
评论数量:1142
留言数量:0
访问次数:9718722
建立时间:2004年12月20日




[java语言]编写安全的代码:数据库连接池的共享
原创空间

邢红瑞 发表于 2005/4/18 12:34:23

最近公司用weblogic的连接池连接oracle数据库,只要是oracle死掉或网络断掉,不但重启oracle,还必须重新启动weblogic,这个问题几年前,就遇到了,听说可以设定为autoconnect,没有试过。稳定性远不如jboss的jmx的连接池,无论oracle如何重起,jboss一直保持连接,我们boss服务器最长1年没有重启。从tomcat 5.0.18之后,dbcp连接池稳定了很多,成了spring的标准配置。 看了agilejava的blog(http://agilejava.blogbus.com/logs/2005/04/1104185.html),知道还有一家比较烂的,IBM的websphere,事务处理有问题。我估计原因是这样的,是<res-sharing-scope>Sharable</res-sharing-scope>的设置,他告诉数据源,在同一事务中,事务由容器或JTA控制,如果被请求多次是否每次返回一个唯一的连接。如果使用不当,连接池马上被用光,导致程序假死。如果大家使用jdbc控制事务,连接不会被共享,设不设,无所谓的。   以下是决定共享的因素,websphere的,懒得翻译了 The listing here is not an exhaustive one. The product might or might not share connections under different circumstances. Only connections acquired with the same resource reference (resource-ref), which specifies the res-sharing-scope as Shareable, are candidates for sharing. The resource-ref properties of res-sharing-scope, res-auth, and res-isolation-level help determine if it is possible to share a connection. The res-isolation-level is a WebSphere extension.   You can only share connections that are requested with the same properties. Connection Sharing only occurs between different component instances if they are within a transaction (container- or user-initiated transaction).  Connection Sharing only occurs within a sharing boundary. Current sharing boundaries include Transactions and LocalTransactionContainment (LTC) boundaries. Within an LTC Scope for shareable connections, only Connection Reuse is allowed within a single component instance. Connection reuse occurs when the following actions are taken with a connection: get, use, commit/rollback, close; get, use, commit/rollback, close. Note that if you use the LTC resolution-control of ContainerAtBoundary then no start/commit is needed because that action is handled by the container. The connection returned on the second get is the same connection as that returned on the first get (if the same properties are used). Because the connection use is serial, only one connection handle to the underlying physical connection is used at a time, so true connection sharing does not take place. The term “reuse” is more accurate. This reuse feature enables an application to issue multiple getConnection() requests from a single dataSource (connection pool) within a single phase transaction. You cannot set the IsolationLevel when using a shareable connection for the JDBC API using a relational resource adapter in a global transaction. The product provides an extension to the resource reference to enable you to specify the isolation level. If your application requires the use of multiple isolation levels, create multiple resource references and map them to the same data source or connection factory.Connection handles: A connection handle is a representation of a physical connection. To use a back end resource (such as a relational database) in the WebSphere Application Server - Express you must get a connection to that resource. When you call the getConnection() method, you get a connection handle returned. The handle is not the physical connection. The physical connection is managed by the connection manager. There are two significant configurations or usage patterns that affect how connection handles are used and how they behave. The first is the res-sharing-scope, which is defined by the resource-reference used to look up the DataSource or Connection Factory. This property tells the connection manager whether or not you can share this connection.


阅读全文(6489) | 回复(1) | 编辑 | 精华
 


回复:编写安全的代码:数据库连接池的共享
原创空间

easywgq(游客)发表评论于2007/11/13 16:50:48

你好,能不能请教你下:在网路断过的情况下,不用重启websphere的应用,可自动连上数据库?


个人主页 | 引用回复 | 主人回复 | 返回 | 编辑 | 删除
 


» 1 »

发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.063 second(s), page refreshed 144799076 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号