users@glassfish.java.net

Re: Sharing a Connection between EJB's

From: Cheng Fang <Cheng.Fang_at_Sun.COM>
Date: Mon, 22 Oct 2007 15:23:59 -0400

> When there is a call from one EJB method to another EJB method, 2 connections are used (each EJB has XXXDataSource.getConnection) .

As I said in previous reply, only 1 connection is used at runtime, not
2, if you close it properly after each use. Connection objects are all
stateless. All connections from the same pool are considered the same.
Why do you care they are the same object? These are all low-level
details that are better handled by appservers. The very purpose of
connection pool in appserver is to make efficient use of connection
resource, which is what you want.

Another (bad) option is to pass the connection as method param from ejb1
to ejb2, if it's a local call. I would not do it this way, but at least
you can make sure they are the same object. If you still have
questions, some sample code may help us better understand your use case.

-cheng


> What I'm asking, is how can I share that the same Connection (same object!) will be used on both EJBs. My concern is not transactions!!! My concern is that I have limited amount of connections in my connection pool. Is it possible without developing somthing of my own or can I use a feature from the application server?
>
>