多线程使用DriverManagerDataSource报创建连接失败问题

在本地运行的时候,多线程操作数据会产生这样一个错误。查找了一些资料后发现: 
DriverManagerDataSource建立连接是只要有连接就新建一个connection,根本没有连接池的作用。改为以下开源的连接池会好点(org.apache.commons.dbcp.BasicDataSource)。
 


Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The driver was unable to create a connection due to an inability to establish the client portion of a socket. 

This is usually caused by a limit on the number of sockets imposed by the operating system. This limit is usually configurable. 

For Unix-based platforms, see the manual page for the 'ulimit' command. Kernel or system reconfiguration may also be required. 

For Windows-based platforms, see Microsoft Knowledge Base Article 196271 (Q196271). 


<!--数据源连接池配置如下:-->  
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">  
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />  
        <property name="url" value="jdbc:mysql://IP:3306/数据库名" />  
        <property name="username" value="username" />  
        <property name="password" value="password" />  
</bean>  

猜你喜欢

转载自blog.csdn.net/qq_34097912/article/details/81062866