JBoss数据库连接池
我是 jboss 的新手,我被要求将 jboss 连接池机制与现有的 Web 应用程序合并。 考虑到 Web 应用程序数据库层已正确编写,即所有结果集、语句和连接在不需要时正确关闭,在正确配置 jboss 数据源后,我必须在 Web 应用程序中进行哪些所有代码更改。
任何人都可以向我指出在 Web 应用程序中使用 jboss 数据源的教程或代码示例吗?
I am new to jboss and i have been asked to incorporate jboss connection pooling mechanism with an existing web application. Considering that a web application database layer is properly written i.e. all resultsets, statements and connections being closed properly when not needed, What all code changes i will have to make in my web app after i have configured the jboss datasource properly.
Can anybody please point me to a tutorial or a code sample which uses jboss datasource in a web app.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先创建一个名为
xxx-ds.xml
的 xml 文件,并将该文件放入server/default/deploy/xxx-ds.xml
< strong>
jboss-web.xml
web.xml
现在位于您的
.java
文件中* **** 确保资源引用名称在所有地方都应该相同
first create an xml file by name
xxx-ds.xml
and place this file inserver/default/deploy/xxx-ds.xml
jboss-web.xml
web.xml
and now in your
.java
file***** make sure that resource ref name should be same in all place
JBoss 中的池全部在 DataSource 配置中处理。 这里是操作方法。 Web 应用程序必须对数据源进行 JNDI 查找才能获取数据库连接,而不是直接执行 JDBC URL,然后您将拥有池化功能。
不过,交易则是另一回事了。
编辑:为了回应您关于这如何影响代码的评论,这就是它的样子:
从技术上讲,PortableRemoteObject.narrow 在 JBoss (无论如何 4.2.2)单服务器配置中肯定是不必要的,但它更重要正确的 J2EE 标准代码,因为一般应用程序服务器不必仅为执行 Context.lookup 而返回正确类型的对象。
以上并未涵盖资源利用和错误处理问题。 当你使用完 Context 对象后,你应该关闭它,当然还有数据库连接,尽管如果你忘记关闭数据库连接并且事务结束,JBoss 会对你大喊大叫,并为你关闭它。
无论如何,该 Connection 对象与 DriverManager.getConnection(url); 一样可用。
The pool in JBoss is all handled in the DataSource configuration. Here is the HowTo. The web app would have to do a JNDI lookup for the datasource to get the database connection rather than doing a direct JDBC URL, and then you will have pooling.
Transactions are another story, though.
EDIT: In response to your comment about how this affects the code, this is what it looks like:
Technically speaking the PortableRemoteObject.narrow isn't necessary in a JBoss (4.2.2 anyway) single server configuration for sure, but it is more proper J2EE standard code, as general application servers don't have to return an object of the right type just for doing a Context.lookup.
The above doesn't cover the resource utilization and error handling issues. You are supposed to close that Context object when you are done with it, and of course the database connection, although JBoss will yell at you if you forget to close the database connection and the transaction ends, and close it for you.
Anyway, that Connection object is usable just as much as DriverManager.getConnection(url);
你不需要改变任何东西。
当您选择正确类型的数据源(local-tx-datasource / xa-datasource)时,连接处理和 TX 就会为您完成。 在 $JBoss/docs/examples/jca 中,您将找到几乎每个数据库的模板,您可以重复使用它们。
如果您使用XA,则需要配置Tx-recovery。 请参阅此帖子以了解操作方法:
http://management-platform.blogspot.com/ 2008/11/transaction-recovery-in-jbossas.html(好吧,也许不是独立模式下的操作方法,而是与 Jopr 源代码结合使用)。
You don't have to change anything.
When you select the right kind of data source (local-tx-datasource / xa-datasource), connection handling and TX is done for you. In $JBoss/docs/examples/jca you will find templates for virtually every database, that you can just reuse.
If you are using XA, you need to configure Tx-recovery. See this posting on a how-to:
http://management-platform.blogspot.com/2008/11/transaction-recovery-in-jbossas.html (well, perhaps not a how-to in the standalone mode, but in conjunction with the Jopr source code).