Search code examples
javatomcatjndi

Tomcat Connection Pooling Multiple Data Sources


If I have configured a JNDI resource in Tomcat and in my code I create two DataSource objects referencing the same JNDI resource will this create two different connection pools or will the DataSources share the same connection pool? If possible could you provide resources that support your answer, I have searched all over and cannot find anything.


Solution

  • They will use the same connection pool.

    What you are declaring is a reference to the real connection pool declared on tomcat so in you case you have 2 references.

    If you want to be sure make a test by leaking a connection on one datasource and display size of the 2 datasources.

    As for reference look at oracle jndi tutorials and tomcat doc configuration of connectio pools.

    Regards

    Philippe M.