Question

We have a web site using spring. I found in the code 2 ways of connecting to the oracle database, both use a bean called phareDataSource :

1st method :

<bean id="phareDataSource"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property name="driverClassName"
        value="oracle.jdbc.driver.OracleDriver" />
    <property name="url"
        value="${hibernate.connection.url}" />
    <property name="username" value="${hibernate.connection.username}" />
    <property name="password" value="${hibernate.connection.password}" />
</bean>

and 2nd method :

<bean id="phareDataSource"
    class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
        <value>jdbc/PHARE</value>
    </property>
</bean>

In Jonas Directory : jonas.properties

jonas.service.dbm.class    org.ow2.jonas.dbm.internal.JOnASDataBaseManagerService
jonas.service.dbm.datasources    PHARERH

PHARERH.properties :

datasource.name     jdbc/PHARE
datasource.url      jdbc\:oracle\:thin\:@blabla\:1521\:R59A001
datasource.classname    oracle.jdbc.driver.OracleDriver
datasource.username         bla
datasource.password         bla

The first method or the second one is picked when we are building (maven active profile).

The first uses a simple configuration file, the second uses a configuration file located in jonas conf directory.

Since we use tomcat in our dev environment, we picked the first method.

But in our int and prod environment with Jonas installed, shouldn't we use the second method ?

Is it better in performance ?

Was it helpful?

Solution

Both will use a JDBC connection pool to manage your connections so I would not expect there to be a major difference in performance.

Method 1 doesn't use any of the JOnAS features to create or manage the JDBC connections + pool. The same configuration will work outside of the application server. This is useful for testing without the requirement to deploy to the application server.

Method 2 will use the JDBC connection pool configured and managed by JOnAS (the application server).

Typically, if you have made the decision to go with an application container (e.g. JOnAS, JBoss, Websphere, etc) it is usually a good idea to let the container manage the resources that you use. That's what they are designed to do, and you may require some of the advanced features for managing the configured resources. There is also the benefit that your application doesn't have to know what implementation/driver is being used (or username/password, so you can deploy your EAR/WAR to different application servers without having to change your application configuration. These details are configured in the server instance instead.

If using Method 1 inside an application server, the server will have no control over the threads being created, because it knows nothing about them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top