On Tue, 2 Oct 2001, Will Stranathan wrote:

> Date: Tue, 02 Oct 2001 13:21:39 -0500
> From: Will Stranathan <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> Subject: Rebinding Resolved Objects
>
> Unfortunately, I've deleted the message, so I can't just
> respond to it, but Remy noted that Catalina doesn't rebind
> resolved objects in the JNDI implementation.
>

I don't think you want to rebind *every* object universally - sometimes
the factory really is a factory.

In the case of the JDBC data source implementation, though, the objective
is to share the DataSource implementation itself, which therefore means
that the underlying connections in the pool will be shared across all
users of the DataSource.

> After I thought about this some, I don't really know how I
> feel about that....
>
> I KNOW that MVC is probably the better way to go, so using a
> single controller servlet is the best idea to handle this,
> but for people who aren't ready to migrate to that, putting
> something like:
>
> DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/Foo");
>
> in the init() of every servlet returns a different
> DataSource from every other servlet.  So a connection pool
> is only valid for that particular servlet.
>

The typical usage of lookup() in J2EE apps has you doing the lookup on
every single need for a connection, and not keeping the connection:

  DataSource ds = (DataSource)
    ctx.lookup("java:comp/env/jdbc/Foo");
  Connection conn = ds.getConnection();
  ... use the connection ...
  conn.close();   // Returns connection to the pool

> Again, I know that the right thing to do is to use a
> controller servlet anyhow, but for those who don't do it,
> they're creating new pools on every page - even when they're
> careful to do otherwise.
>
> Incidentally, I'm STILL getting new connections on every
> request to getConnection().  Somebody else had posted to try
> to use PooledConnectionDataSource, but even that creates new
> connections.  Does the specific JDBC driver need to
> implement something special to work correctly?  i.e., has
> anybody gotten pooling to work properly with mm.mysql, or
> FreeTds?
>

The existing factory for Tyrex *always* creates a new data source
implementation when you call lookup().

> Thanks,
> Will Stranathan
>

Craig


Reply via email to