Introduction : ODS or UCP?
So, this post is my history with Oracle pool.
When you look for pool features on Oracle doc website, you find to ways to implement it :
- Oracle DataSource pool (also called ODS) and included in the driver jar file
- Oracle Universal Connection Pool (UCP), which is packaged in its own jar file (ucp.jar)
ODS : the old way
<bean id="OracleNativePoolParent" class="oracle.jdbc.pool.OracleDataSource"
destroy-method="close" lazy-init="true" >
<property name="user" value="****" />
<property name="password" value="****" />
<property name="serverName" value="****" />
<property name="databaseName" value="****" />
<property name="driverType" value="thin" />
<property name="networkProtocol" value="tcp" />
<property name="portNumber" value="1521" />
<property name="connectionCachingEnabled" value="true" />
<property name="connectionCacheProperties">
<props merge="default">
<prop key="InitialLimit">1</prop>
<prop key="MinLimit">1</prop>
<prop key="MaxLimit">10</prop>
</props>
</property>
<property name="maxStatements" value="400" />
<property name="loginTimeout" value="20" />
<property name="connectionProperties">
<props merge="default">
<prop key="AutoCommit">false</prop>
</props>
</property>
</bean>
UCP : you should use it instead of ODS
Now, let's switch to UCP. Curiously, We need to use a factory to obtain an instance of this pool. This is my Spring configuration :
<bean id="OracleNativePoolParent" class="oracle.ucp.jdbc.PoolDataSourceFactory" factory-method="getPoolDataSource" lazy-init="true" >
<property name="connectionFactoryClassName" value="oracle.jdbc.pool.OracleDataSource"/>
<property name="user" value="****" />
<property name="password" value="****" />
<property name="URL" value="jdbc:oracle:thin:@myServer:1521:myDB" />
<property name="connectionWaitTimeout" value="30" />
<property name="minPoolSize" value="1"/>
<property name="maxPoolSize" value="10"/>
<property name="inactiveConnectionTimeout" value="3600"/>
<property name="validateConnectionOnBorrow" value="true"/>
<property name="maxStatements" value="400"/>
<property name="connectionProperties">
<props merge="default">
<prop key="AutoCommit">false</prop>
</props>
</property>
</bean>
Driver Oracle 11g blocked on startup
While initializing your pool, you have to wait 5 minutes then get an exception? Don't panic. It's just a little but with Sun Java on Linux OS. Add this JVM parameter :
-Djava.security.egd=file:///dev/urandom
More informations here : http://www.usn-it.de/index.php/2009/02/20/oracle-11g-jdbc-driver-hangs-blocked-by-devrandom-entropy-pool-empty/
Conclusion
Even if I didn't find all the options I had with C3P0, UCP seems to be efficient for me. I think that it's a best choice to work with Oracle database because it is officially supported. But, there's still a negative point. As I don't have the source code, it will be very difficult to qualify bugs and to understand advanced parameters (and I think that the official documentation is not exhaustive at all).