[Spring + Hibernate] Configure connection pool with Spring based – c3p0, Apache DBCP and BoneCP

Application Context

1. Without connection pool

</pre>
<!-- Data Source Declaration -->
<bean id="myDataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>

2. c3p0

</pre>
<!-- C3P0 Connection Pool -->
<bean id="c3p0" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="${db.url}" />
<property name="user" value="${db.username}" />
<property name="password" value="${db.password}" />

<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="maxStatements" value="50" />
<property name="idleConnectionTestPeriod" value="3000" />
<property name="loginTimeout" value="300" />
</bean>

3. Apache DBCP

</pre>
<!-- DBCP configuration -->
<bean id="dbcp" class="com.jolbox.bonecp.BoneCPDataSource"
destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="removeAbandoned" value="true" />
<property name="initialSize" value="20" />
<property name="maxActive" value="30" />
</bean>
<pre>

4. BoneCP

</pre>
<!-- BoneCP configuration -->
<bean id="boneCP" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClass" value="org.postgresql.Driver" />
<property name="jdbcUrl" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="idleConnectionTestPeriodInMinutes" value="60" />
<property name="idleMaxAgeInMinutes" value="240" />
<property name="maxConnectionsPerPartition" value="30" />
<property name="minConnectionsPerPartition" value="10" />
<property name="partitionCount" value="3" />
<property name="acquireIncrement" value="5" />
<property name="statementsCacheSize" value="100" />
</bean>
<pre>

and session factory declaration…

</pre>
<!-- Session Factory Declaration -->
<bean id="mySessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" /> <!-- without connection pool -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
<prop key="hibernate.default_schema">myagile</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<pre>

Reference:
[1]. http://jolbox.com/
[2]. http://www.javacodegeeks.com/2012/04/jsf-2-primefaces-3-spring-3-hibernate-4.html
[3]. http://www.mchange.com/projects/c3p0/
[4]. http://www.mkyong.com/hibernate/how-to-configure-the-c3p0-connection-pool-in-hibernate/

Advertisements

Posted on 07/12/2013, in Java, Spring - Hibernate and tagged , . Bookmark the permalink. Bạn nghĩ gì về bài viết này?.

Trả lời

Mời bạn điền thông tin vào ô dưới đây hoặc kích vào một biểu tượng để đăng nhập:

WordPress.com Logo

Bạn đang bình luận bằng tài khoản WordPress.com Đăng xuất / Thay đổi )

Twitter picture

Bạn đang bình luận bằng tài khoản Twitter Đăng xuất / Thay đổi )

Facebook photo

Bạn đang bình luận bằng tài khoản Facebook Đăng xuất / Thay đổi )

Google+ photo

Bạn đang bình luận bằng tài khoản Google+ Đăng xuất / Thay đổi )

Connecting to %s

Advanced programming

Tự học lập trình Android, android wear - lập trình smartwatch, Windows phone, Web service, C++, C#, java, Swift, Python, kotlin...

Tôi IT - Change the world

Research + Technical -> Programming,

juliansherman.net/

Building A Business While Having A Life

VN.NVANHUONG

No Pain No Gain

Study and Share's Blog

Việt Nam tươi đẹp...

Broly

One of the best way to learn is by writing to the paper.

%d bloggers like this: