I have a stateless session beans that request a bunch of datasource connections from a pool (JBOSS/Minerva).
Do I have to close the connections I requested explicitly? I seem to recall that I am not allowed to close the connection or in anyway manipulate the autocommit flag.
However, if I don't close the connections, soon enough, I'd use up all connections in the pool and with Minerva, either my EJB gets blocked or it has to be able to handle a failure condition.
So, my question is, do I have to close the connections I look up through JNDI and datasource.getConnection() explicitly? Thanks.
-
Closing a Database Connection (4 messages)
- Posted by: Digit Sequence
- Posted on: May 21 2001 02:52 EDT
Threaded Messages (4)
- Closing a Database Connection by qing yan on May 21 2001 03:03 EDT
- Closing a Database Connection by Digit Sequence on May 21 2001 03:26 EDT
- Closing a Database Connection by qing yan on May 21 2001 11:54 EDT
- Closing a Database Connection by sanjib ghosh on May 22 2001 02:38 EDT
- Closing a Database Connection by Digit Sequence on May 21 2001 03:26 EDT
-
Closing a Database Connection[ Go to top ]
- Posted by: qing yan
- Posted on: May 21 2001 03:03 EDT
- in response to Digit Sequence
There are different ways to keep the db connections,
in your case, you probably need to do CloseConn() more
frequently, what it will do is returning the connection
to the connection pool not really closing..
And keep your transactions short, or you won't be able
to free the connection. -
Closing a Database Connection[ Go to top ]
- Posted by: Digit Sequence
- Posted on: May 21 2001 03:26 EDT
- in response to qing yan
The problem is that each of my transaction involve multiple connections. So you are saying that doing this in my stateless session bean:
dataSource = initialCtx.lookup("blablaba/datasource");
Connection conn = dataSource.getConnection();
blablalaba;
conn.close();
does not violate EJB spec and create problems with container managed transactions for stateless session beans?
I know that doing this conn.setAutoCommit(true) is supposedly a very bad thing to do in a container managed transaction scenario.
-
Closing a Database Connection[ Go to top ]
- Posted by: qing yan
- Posted on: May 21 2001 11:54 EDT
- in response to Digit Sequence
It is ok and leave the job to the app server.
The problem if you have a long span transaction,you will still hold the connection,if the app server is smart
enought it should reuse the same connection for the
same transaction. -
Closing a Database Connection[ Go to top ]
- Posted by: sanjib ghosh
- Posted on: May 22 2001 02:38 EDT
- in response to Digit Sequence
In container managed transactions, you should not call Connection methods commit, rollback and setAutoCommit(true).
However,as qing said,you should close it as soon as you are done with it so that it can be reused.
thanks...sanjib