my.ini 里面设置了 max_connections = 1000
客户端使用Delphi开线程 模仿1000个用户对数据库(mysql)进行插入数据
正常无错误信息的情况下可以插入数据`我查看数据库有数据了!
但是大概1分钟左右服务器就会暴无法获取数据库连接``证明已经满了
错误信息如下:
Caused by: java.sql.SQLException: Data source rejected establishment of connecti
on, message from server: "Too many connections"
我怀疑没有释放connection
现在不知道如何解决了``以下是所有代码!!!!!!!!!
DAO
package com.xiaomaha.dao;
import java.io.Serializable;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.xiaomaha.po.User;
public class UserDAO extends HibernateDaoSupport {
public void save(User user){
this.getHibernateTemplate().save(user);
}
}
BO
package com.xiaomaha.bo;
import com.xiaomaha.dao.UserDAO;
import com.xiaomaha.po.User;
public class UserBo {
private UserDAO dao;
public UserDAO getDao() {
return dao;
}
public void setDao(UserDAO dao) {
this.dao = dao;
}
public void save(User user){
dao.save(user);
}
}
webservice接口实现类
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.xiaomaha.tools.Pack;
import com.xiaomaha.bo.UserBo;
import com.xiaomaha.dao.UserDAO;
//Generated by MyEclipse
import com.xiaomaha.po.User;
public class testImpl implements Itest {
public String addUser(String message){
try {
//这个是我们通过反射写的工具类以测试过没问题的!
User user = (User) Pack.createObject(User.class, message);
ApplicationContext app= new ClassPathXmlApplicationContext("applicationContext.xml");
UserBo bo = (UserBo) app.getBean("boProxy");
bo.save(user);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return message;
}
public String addUser2(String message) {
return message;
}
}
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>
<bean id="t" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="dao" class="com.xiaomaha.dao.UserDAO">
<property name="hibernateTemplate" ref="t"></property>
</bean>
<bean id="bo" class="com.xiaomaha.bo.UserBo">
<property name="dao" ref="dao"></property>
</bean>
<bean id="transaction" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="boProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager" ref="transaction"></property>
<property name="target" ref="bo"></property>
<property name="transactionAttributes">
<props>
<prop key="save*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
</beans>
hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">root</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/test
</property>
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<property name="myeclipse.connection.profile">mysql</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="show_sql">true</property>
<property name="hibernate.connection.release_mode">after_transaction</property>
<mapping resource="com/xiaomaha/po/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
老紫竹````````和高手们帮帮吧!具体找不到原因了``google,baidu什么都试过!!!!!!1