http://www.cn-java.com/www1/?action-viewnews-itemid-10329

Hibernate's own connection pooling algorithm quite immature. It is only in order to let you get started as soon as possible, not suitable for the product or performance tests. For the best performance and stability you should consider using a third-party connection pool. Just use a specific connection pool settings can be hibernate.connection.pool_size replacement. This will turn off Hibernate's own connection pool. For example, you might want to use C3P0.
C3P0 is distributed with open source Hibernate with the JDBC connection pool, which is located in lib directory. If you set up a property hibernate.c3p0 .* relevant, Hibernate will use JDBC to connect to cache C3P0ConnectionProvider. If you intent to use more Proxool, please refer to the issue of hibernate.properties package and to the Hibernate website for more information.
This is a sample hibernate.properties of the use of C3P0 document (from the Hibernate package etc directory):
############################## C3P0 Connection Pool###############################hibernate.c3p0.max_size 2#hibernate.c3p0.min_size 2#hibernate.c3p0.timeout 5000#hibernate.c3p0.max_statements 100#hibernate.c3p0.idle_test_period 3000#hibernate.c3p0.acquire_increment 2#hibernate.c3p0.validate false 

Add it in the hibernate.cfg.xml file to configure the following:

<!-- 最大连接数 -->        <property name="hibernate.c3p0.max_size">20</property>        <!-- 最小连接数 -->        <property name="hibernate.c3p0.min_size">5</property>        <!-- 获得连接的超时时间,如果超过这个时间,会抛出异常,单位毫秒 -->        <property name="hibernate.c3p0.timeout">120</property>        <!-- 最大的PreparedStatement的数量 -->        <property name="hibernate.c3p0.max_statements">100</property>        <!-- 每隔120秒检查连接池里的空闲连接 ,单位是秒-->        <property name="hibernate.c3p0.idle_test_period">120</property>        <!-- 当连接池里面的连接用完的时候,C3P0一下获取的新的连接数 -->        <property name="hibernate.c3p0.acquire_increment">2</property>        <!-- 每次都验证连接是否可用 -->        <property name="hibernate.c3p0.validate">true</property> 

Integrity of the sample are as follows (hibernate.properties):

hibernate.connection.driver_class = org.postgresql.Driverhibernate.connection.url = jdbc:postgresql://localhost/mydatabasehibernate.connection.username = myuserhibernate.connection.password = secrethibernate.c3p0.min_size=5hibernate.c3p0.max_size=20hibernate.c3p0.timeout=1800hibernate.c3p0.max_statements=50hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect