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.
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.
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();
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.
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
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.