简体   繁体   English

在Web应用程序中同时访问数据库

[英]Simultaneous access to Database in Web application

How can I know the average or exact number of users accessing database simultaneously in my Java EE web enterprise application? 如何知道在Java EE Web企业应用程序中同时访问数据库的平均或确切数量? I would like to see if the "Connection pool setting" I set in the Glassfish application server is suitable for my web application or not. 我想看看我在Glassfish应用服务器中设置的“连接池设置”是否适合我的Web应用程序。 I need to correctly set the maximun number of connection in Connection Pool setting in Application Server. 我需要在Application Server的Connection Pool设置中正确设置最大连接数。 Recently, my application ran out of connections and threw exceptions when the client request for DB expires. 最近,当客户端请求数据库过期时,我的应用程序用完连接并抛出异常。

There are multiple ways. 有多种方式。

One and easiest would be take help from your DBAs - they can tell you exactly how many connections are active from your webserver or the user id for connection pool at a given time. 最简单的方法是从您的DBA那里获得帮助 - 他们可以确切地告诉您在您的网络服务器中有多少连接是活动的,或者在给定时间确定连接池的用户ID。

If you want some excitement, you will have to JMX management extensions provided by glassfish. 如果您需要一些兴奋,您将需要使用glassfish提供的JMX管理扩展。 Listing 6 on this page - gives an example as to how to write a JMS based snippet to monitor a connection pool. 此页面上的清单6 - 给出了如何编写基于JMS的代码段来监视连接池的示例。

Finally, you must make sure that all connections are closed explicitly by a connection.close(); 最后,您必须确保connection.close();显式关闭所有连接connection.close(); type of call in your application. 您的应用程序中的呼叫类型。 In some cases, you need to close ResultSet as well. 在某些情况下,您还需要关闭ResultSet。 Next is throttling your http thread pool to avoid too many concurrent access if your db connections are taking longer to close. 接下来是限制您的http线程池,以避免在您的数据库连接需要更长时间关闭时进行过多的并发访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM