-
1. Re: Jboss connection pools and JDBC
draftdog Dec 2, 2002 12:01 PM (in response to tmyong)hi,
first of all it is important to treat stateless and stateful session beans differently.
Stateless session beans do not maintain state information. All instances of a stateless session bean are considered to be identical (you can have more in a clustered environment for example), typically you allocate and release the DB connection in the (short) lifetime of the bean, this can be real a performance killer since there is no shared resource and you introduce the overhead of creation/destruction each time.
On the other hand, each instance of a particular stateful session bean is unique, and therefore each request for a connection to a datasource will _normally_ result in a new connection, as you already expected.
For the stateful example you could code a singleton pattern (for this bean only) that caches the connection and returns the same instance once it has one, this way you would ask a connection to your bean instead of directly to the DataSource you are using (be it JBoss, Oracle, etc...)
so, something like this:
public class MyStatefulSessionBean ...
{
private static Connection connection = null;
private synchronized Connection getConnection()
{
if (connection == null)
{
connection = dataSource.getConnection();
}
return connection;
}
}
personally I try to avoid static members, especially in J2EE apps using complex ClassLoader hierarchies.
Another alternative would be configuring your datasource to allow only one connection for the bean, dont ask me how , I am more of a CMP guy myself ;-)
if somebody out there knows how to do this, I would like to know.
anyway, to answer your question: I am pretty sure the JBoss implementation of the DataSource does not share connections by default for a session bean.
cheers
Wouter.