You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Mark Thomas (JIRA)" <ji...@apache.org> on 2014/02/11 22:06:22 UTC

[jira] [Commented] (DBCP-309) First example for FSContext is invalid

    [ https://issues.apache.org/jira/browse/DBCP-309?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13898311#comment-13898311 ] 

Mark Thomas commented on DBCP-309:
----------------------------------

Caveat: I am no JNDI expert. The little I do know is gleaned from reverse engineering Tomcat's JNDI implementation.

I think the example is wrong because it binds a reference. A reference will always result in a new object being created when it is looked up. If the example binds a BasicDataSource instance, it appears to behave as desired/expected.

As most users expect multiple JNDI look ups using the same name to return the same object, Tomcat deliberately breaks the rules. By default, when Tomcat finds a reference, Tomcat resolves that reference to an object and then replaces the reference in JNDI with the object. In later Tomcat versions, this is configurable with the singleton property.

It isn't clear to me how implementing Referenceable will help. If anything, that will make it worse as it would then be impossible to bind an instance of a BasicDataSource to JNDI as the Reference would be bound.

I intend to tweak the examples to bind instances rather than References. This appears to be consistent with Ondrej Tisler's approach above.

> First example for FSContext is invalid
> --------------------------------------
>
>                 Key: DBCP-309
>                 URL: https://issues.apache.org/jira/browse/DBCP-309
>             Project: Commons Dbcp
>          Issue Type: Bug
>    Affects Versions: 1.2.2
>            Reporter: Ondrej Tisler
>            Priority: Trivial
>             Fix For: 1.3.1, 1.4.1
>
>
> First example on page http://commons.apache.org/dbcp/guide/jndi-howto.html is invalid, with this code every call of  
>   InitialContext ic2 = new InitialContext();
>   DataSource ds = (DataSource) ic2.lookup("jdbc/basic");
>   Connection conn = ds.getConnection();
>   conn.close();
> ends with new datasource with unclosed connection in it becase new Reference("javax.sql.DataSource",  "org.apache.commons.dbcp.BasicDataSourceFactory", null); reference creates new DataSource instead using created one while calling  ic2.lookup("jdbc/basic").
> At the end it ends with many opened connections to DB until JVM is ended.
> Second example I didn't test, i use direct aproach with manualy creating SharedPoolDataSource and registring it in FSContext JNDI itself.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)