`
superfofo
  • 浏览: 129939 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

DriverManagerDataSource

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

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>

测试通过,问题消除
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

被不知道谁忽悠了我很长一段时间,误认为DriverManagerDataSource这东西就是一个连接池,这下傻了
分享到:
评论
2 楼 ml365 2010-12-24  
org.apache.commons.dbcp.BasicDataSource

刚确认了下。我们还是用这个。还好
1 楼 ml365 2010-12-24  
汗。。我目前写的项目好像也是依赖DriverManagerDataSource

相关推荐

    Spring使用DriverManagerDataSource和C3P0分别配置MySql6.0.6数据源

    本篇将深入探讨如何使用`DriverManagerDataSource`和C3P0两种不同的数据源来配置MySQL 6.0.6数据库连接。我们将从它们的基本概念、配置过程以及优缺点等方面进行详细阐述。 首先,`DriverManagerDataSource`是...

    酒店住宿管理系统 用EXT+Spring+Hibernate(上)

    酒店住宿管理系统采用EXT+Spring+...修改数据库密码 &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="password" value="neostudio"/&gt; &lt;/bean&gt;

    spring的持久层封装

    这里,`DriverManagerDataSource`被用来处理数据库连接,并通过属性如`driverClassName`、`url`、`username`和`password`进行配置。 2. **使用DBCP连接池** 要在Spring中使用DBCP连接池,需要添加额外的依赖库,...

    Spring配置数据源的三种方式 (dbcp,c3p0,jndi)..docx

    本文将详细介绍Spring配置数据源的三种常见方式:`DriverManagerDataSource`、`Apache Commons DBCP`(BasicDataSource)以及通过`JNDI`查找数据源。 1. **DriverManagerDataSource** `DriverManagerDataSource`是...

    关于SpringMyBatis纯注解事务不能提交的问题分析与解决

    具体来说,当使用`DriverManagerDataSource`作为数据源时,MySQL事务可以正常提交,但Oracle事务却不能提交。这表明问题可能出在数据源的选择上。 ### 问题分析 #### 数据源的选择 在Spring中,有多种数据源可供...

    Spring学习笔记(10)----公共属性的注入配置

    DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/mydb"); dataSource....

    JAVA基于SSM的java智能制造系统源码数据库 MySQL源码类型 WebForm

    基于SSM的java智能制造系统源码 更新内容:新增车间管理模块 新增生产订单模块 ... Javascript 3....class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="password" valu

    mybatis-4 mybatis与spring结合使用及原理解析

    DriverManagerDataSource dataSource = new DriverManagerDataSource(); // 设置数据库连接信息 dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/...

    SpringBoot-data.zip

    DriverManagerDataSource dataSource = new DriverManagerDataSource(); // 配置MySQL数据库连接信息 dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:...

    Spring 数据源的灵活配置巧应用

    &lt;bean id="rptds" class="org.springframework.jdbc.datasource.DriverManagerDataSource" destroy-method="close"&gt; &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt; &lt;value&gt;jdbc:mysql://localhost:3306/testdb ...

    SpringJdbc.rar

    DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(url); dataSource.setUsername(username); dataSource....

    Spring笔试试卷.doc

    - Spring提供了多种数据源实现,例如`DriverManagerDataSource`,它简单但不支持连接池,适合轻量级应用。 - A选项错误,`DriverManagerDataSource`不支持连接池。 - B选项正确,Spring可以使用Apache的DBCP或C3P...

    springboot在项目中集成 mysql,sqlserver多数据源项目源代码.zip

    DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl(this.url); dataSource.setUsername(this.username); ...

    Spring数据库访问(HSQL)(四)

    DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("org.hsql.jdbcDriver"); dataSource.setUrl("jdbc:hsqldb:mem:testdb"); dataSource.setUsername("sa");...

    spring笔记.docx

    DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName("com.mysql.jdbc.Driver"); dataSource.setUrl("jdbc:mysql://localhost:3306/mydb"); dataSource....

    spring boot多数据源

    DriverManagerDataSource dataSource = new DriverManagerDataSource(); dataSource.setDriverClassName(primaryConfig.getDriverClassName()); dataSource.setUrl(primaryConfig.getUrl()); dataSource....

    MF00289-基于SSM的java智能制造系统源码.zip

    基于SSM的java智能制造系统源码 开发语言 : JAVA 数据库 : MySQL 开发工具 : Eclipse 源码类型 : WebForm 注意:不带技术支持,...class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;/bean&gt;

    spring多数据库

    return new DriverManagerDataSource(); } @ConfigurationProperties(prefix = "db2") @Bean public DataSource db2DataSource() { return new DriverManagerDataSource(); } ``` 接下来,Spring的`@Autowired`...

    jdbc-ldap spring

    class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; ${ldap.datasource.driverClassName}" /&gt; ${ldap.datasource.url}" /&gt; ${ldap.datasource.username}" /&gt; ${ldap.datasource....

Global site tag (gtag.js) - Google Analytics