多執行緒使用DriverManagerDataSource報建立連線失敗問題
阿新 • • 發佈:2019-02-07
在本地執行的時候,多執行緒操作資料會產生這樣一個錯誤。查找了一些資料後發現:
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.
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>