hibernate连接池
我分别用以下链接方式测试了一下:
tomcat自带的连接池
<propertyname="connection.datasource">java:comp/env/jdbc/mysqlds</property>
JDBC直接连接
<propertyname="hibernate.connection.url">jdbc:mysql://localhost:3333/message</property>
<propertyname="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<propertyname="hibernate.connection.username">root</property>
<propertyname="hibernate.connection.password">56906950</property>
<propertyname="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<propertyname="hibernate.show_sql">true</property>
<propertyname="hibernate.hbm2ddl.auto">update</property>
#使用c3p0连接池
<propertyname="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<propertyname="hibernate.connection.url">jdbc:mysql://localhost:3333/message</property>
<propertyname="hibernate.connection.username">root</property>
<propertyname="hibernate.connection.password">56906950</property>
<propertyname="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<propertyname="hibernate.c3p0.min_size">8</property>
<propertyname="hibernate.c3p0.max_size">200</property>
<propertyname="hibernate.c3p0.timeout">600</property>
<propertyname="hibernate.c3p0.max_statements">0</property>
<propertyname="hibernate.c3p0.idle_test_period">60</property>
<propertyname="hibernate.c3p0.acquire_increment">2</property>
<propertyname="hibernate.c3p0.validate">true</property>
不知道我上面写的配置是不是正确,但愿不对....
然后写了一个测试方法:
longtime=System.currentTimeMillis();
for(inti=0;i<1000;i++){
Sessionsession=HibernateUtils.getSession();
HibernateUtils.closeSession(session);
}
System.out.println(System.currentTimeMillis()-time);
发现JDBC所花费的时间是最少的2000ms,其次是tomcat自带的连接池2096,c3p0竟然用了4950ms!
不是说c3p0是最成熟的吗?为何是这种情况,还是我写的测试方法不是很有效呢?谢谢啊