最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > jsp教程

jsp开发中tomcat频繁死掉的问题

日期:09-14    来源:中国设计秀    作者:cnwebshow.com

某天在服务器上的网页打不开了,频繁报以下错误。x2O中国设计秀

2007-3-18 1:08:26 org.apache.tomcat.util.threads.ThreadPool logFullx2O中国设计秀
严重: All threads (150) are currently busy, waiting. Increase maxThreads (150) or check the servlet statusx2O中国设计秀

在网上找了些回答,以下是我觉得正确的回答:x2O中国设计秀
1.我想你的部分资源没有释放,积压卡死的x2O中国设计秀
2.连接池问题x2O中国设计秀
3.应该是服务器端响应request的线程的处理时间过长导致的x2O中国设计秀

分析:x2O中国设计秀
当时使用网站的人数只有2个人,不可能答到到了并发线程150的上线。所以应该不是数据库的问题。x2O中国设计秀
通过对出错的提示判断,应该是连接池使用不合理造成的,或者根本没设置连接池。和数据库连接的部分是使用SPRing的数据源JDBC连的,如下:x2O中国设计秀
<beans>x2O中国设计秀
    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">x2O中国设计秀
        <!-- driver for MySQL-->x2O中国设计秀
        <property name="driverClassName"><value>org.gjt.mm.mysql.Driver</value></property>x2O中国设计秀
        <property name="url"><value>jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF8</value></property>x2O中国设计秀
        <property name="username"><value>test</value></property>x2O中国设计秀
        <property name="password"><value>test</value></property>       x2O中国设计秀
</beans>x2O中国设计秀

问题应该出现在Spring的DriverManagerDataSource上,它负责管理这些连接的。x2O中国设计秀
下边是对DriverManagerDataSource 的解释x2O中国设计秀
DriverManagerDataSource in Spring Frameworkx2O中国设计秀

   javax.sql Interface DataSourcex2O中国设计秀

Implementation of SmartDataSource that configures a plain old JDBC Driver via x2O中国设计秀
bean properties, and returns a new Connection every time.x2O中国设计秀

Useful for test or standalone environments outside of a J2EE container, either x2O中国设计秀
as a DataSource bean in a respective applicationContext, or in conjunction with x2O中国设计秀
a simple JNDI environment. Pool-assuming Connection.close() calls will simply x2O中国设计秀
close the connection, so any DataSource-aware persistence code should work.x2O中国设计秀

In a J2EE container, it is recommended to use a JNDI DataSource provided by the x2O中国设计秀
container. Such a DataSource can be exported as a DataSource bean in an x2O中国设计秀
ApplicationContext via JndiObjectFactoryBean, for seamless switching to and from x2O中国设计秀
a local DataSource bean like this class.x2O中国设计秀

If you need a "real" connection pool outside of a J2EE container, consider x2O中国设计秀
Apache's Jakarta Commons DBCP. Its BasicDataSource is a full connection pool x2O中国设计秀
bean, supporting the same basic properties as this class plus specific settings. x2O中国设计秀
It can be used as a replacement for an instance of this class just by changing x2O中国设计秀
the class name of the bean definition to x2O中国设计秀
"org.apache.commons.dbcp.BasicDataSource".x2O中国设计秀

-----------------------------------------------x2O中国设计秀
Many Jakarta projects support interaction with a relational database. Creating a x2O中国设计秀
new connection for each user can be time consuming (often requiring multiple x2O中国设计秀
seconds of clock time), in order to perform a database transaction that might x2O中国设计秀
take milliseconds. Opening a connection per user can be unfeasible in a x2O中国设计秀
publicly-hosted Internet application where the number of simultaneous users can x2O中国设计秀
be very large. Accordingly, developers often wish to share a "pool" of open x2O中国设计秀
connections between all of the application's current users. The number of users x2O中国设计秀
actually performing a request at any given time is usually a very small x2O中国设计秀
percentage of the total number of active users, and during request processing is x2O中国设计秀
the only time that a database connection is required. The application itself x2O中国设计秀
logs into the DBMS, and handles any user account issues internally.x2O中国设计秀

There are several Database Connection Pools already available, both within x2O中国设计秀
Jakarta products and elsewhere. This Commons package provides an opportunity to x2O中国设计秀
coordinate the efforts required to create and maintain an efficient, x2O中国设计秀
feature-rich package under the ASF license.x2O中国设计秀

The commons-dbcp package relies on code in the commons-pool package to provide x2O中国设计秀
the underlying object pool mechanisms that it utilizes.x2O中国设计秀

Applications can use the commons-dbcp component directly or through the existing x2O中国设计秀
interface of their container / supporting framework. For example the Tomcat x2O中国设计秀
servlet container presents a DBCP DataSource as a JNDI Datasource. James (Java x2O中国设计秀
Apache Mail Enterprise Server) has integrated DBCP into the Avalon framework. A x2O中国设计秀
Avalon-style datasource is created by wrapping the DBCP implementation. The x2O中国设计秀
pooling logic of DBCP and the configuration found in Avalon's excalibur code is x2O中国设计秀
what was needed to create an integrated reliable DataSource.x2O中国设计秀

看完了解释,事实上是因为DriverManagerDataSource建立连接是只要有连接就新建一个connection,根本没有连接池的作用。改为以下开源的连接池会好点。x2O中国设计秀
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> x2O中国设计秀
<property name="driverClassName"> x2O中国设计秀
<value>org.hsqldb.jdbcDriver</value> x2O中国设计秀
</property> x2O中国设计秀
<property name="url"> x2O中国设计秀
<value>jdbc:hsqldb:hsql://localhost:9001</value> x2O中国设计秀
</property> x2O中国设计秀
<property name="username"> x2O中国设计秀
<value>sa</value> x2O中国设计秀
</property> x2O中国设计秀
<property name="password"> x2O中国设计秀
<value></value> x2O中国设计秀
</property> x2O中国设计秀
</bean>x2O中国设计秀

测试通过,问题消除,如果没有搜索引擎找答案不会这么快解决问题。x2O中国设计秀

本文引用地址:/bc/article_46648.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明