分享
 
 
 

tomcat频繁死掉的问题

王朝system·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

某天在服务器上的网页打不开了,频繁报以下错误。

2007-3-18 1:08:26 org.apache.tomcat.util.threads.ThreadPool logFull

严重: All threads (150) are currently busy, waiting. Increase maxThreads (150) or check the servlet status

在网上找了些回答,以下是我觉得正确的回答:

1.我想你的部分资源没有释放,积压卡死的

2.连接池问题

3.应该是服务器端响应request的线程的处理时间过长导致的

分析:

当时使用网站的人数只有2个人,不可能答到到了并发线程150的上线。所以应该不是数据库的问题。

通过对出错的提示判断,应该是连接池使用不合理造成的,或者根本没设置连接池。和数据库连接的部分是使用Spring的数据源JDBC连的,如下:

<beans>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

<!-- driver for MySQL-->

<property name="driverClassName"><value>org.gjt.mm.mysql.Driver</value></property>

<property name="url"><value>jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF8</value></property>

<property name="username"><value>test</value></property>

<property name="password"><value>test</value></property>

</beans>

问题应该出现在Spring的DriverManagerDataSource上,它负责管理这些连接的。

下边是对DriverManagerDataSource 的解释

DriverManagerDataSource in Spring Framework

javax.sql Interface DataSource

Implementation of SmartDataSource that configures a plain old JDBC Driver via

bean properties, and returns a new Connection every time.

Useful for test or standalone environments outside of a J2EE container, either

as a DataSource bean in a respective ApplicationContext, or in conjunction with

a simple JNDI environment. Pool-assuming Connection.close() calls will simply

close the connection, so any DataSource-aware persistence code should work.

In a J2EE container, it is recommended to use a JNDI DataSource provided by the

container. Such a DataSource can be exported as a DataSource bean in an

ApplicationContext via JndiObjectFactoryBean, for seamless switching to and from

a local DataSource bean like this class.

If you need a "real" connection pool outside of a J2EE container, consider

Apache's Jakarta Commons DBCP. Its BasicDataSource is a full connection pool

bean, supporting the same basic properties as this class plus specific settings.

It can be used as a replacement for an instance of this class just by changing

the class name of the bean definition to

"org.apache.commons.dbcp.BasicDataSource".

-----------------------------------------------

Many Jakarta projects support interaction with a relational database. Creating a

new connection for each user can be time consuming (often requiring multiple

seconds of clock time), in order to perform a database transaction that might

take milliseconds. Opening a connection per user can be unfeasible in a

publicly-hosted Internet application where the number of simultaneous users can

be very large. Accordingly, developers often wish to share a "pool" of open

connections between all of the application's current users. The number of users

actually performing a request at any given time is usually a very small

percentage of the total number of active users, and during request processing is

the only time that a database connection is required. The application itself

logs into the DBMS, and handles any user account issues internally.

There are several Database Connection Pools already available, both within

Jakarta products and elsewhere. This Commons package provides an opportunity to

coordinate the efforts required to create and maintain an efficient,

feature-rich package under the ASF license.

The commons-dbcp package relies on code in the commons-pool package to provide

the underlying object pool mechanisms that it utilizes.

Applications can use the commons-dbcp component directly or through the existing

interface of their container / supporting framework. For example the Tomcat

servlet container presents a DBCP DataSource as a JNDI Datasource. James (Java

Apache Mail Enterprise Server) has integrated DBCP into the Avalon framework. A

Avalon-style datasource is created by wrapping the DBCP implementation. The

pooling logic of DBCP and the configuration found in Avalon's excalibur code is

what was needed to create an integrated reliable DataSource.

看完了解释,事实上是因为DriverManagerDataSource建立连接是只要有连接就新建一个connection,根本没有连接池的作用。改为以下开源的连接池会好点。

<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

<property name="driverClassName">

<value>org.hsqldb.jdbcDriver</value>

</property>

<property name="url">

<value>jdbc:hsqldb:hsql://localhost:9001</value>

</property>

<property name="username">

<value>sa</value>

</property>

<property name="password">

<value></value>

</property>

</bean>

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

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有