-
1. Re: Problem with WrappedConnection
eddie07 May 20, 2003 6:27 AM (in response to eddie07)This is the corresponding part of my source code (in ejbCreate because I don't need the connection later):
ds = (javax.sql.DataSource)initContext.lookup(dsName);
conn = ds.getConnection();
Calling another function (part of the same bean) which does this:
WrappedConnection wc = (WrappedConnection)conn;
Connection c = wc.getUnderlyingConnection();
// using connection
wc.close();
wc = null;
c = null;
Return to ejbCreate:
ds = null; -
2. Re: Problem with WrappedConnection
davidjencks May 20, 2003 7:36 AM (in response to eddie07)where is the conn = null; line.
Generally I recommend NOT having an instance variable for a connection but obtaining it only when needed and closing it immediately. -
3. Re: Problem with WrappedConnection
eddie07 May 21, 2003 9:30 AM (in response to eddie07)> where is the conn = null; line.
ups, this was the problem.
Nevertheless I still have the problem that the bean can't be passivated, now because of an open socket. I know it's not a good idea to do this but I must have/keep an open socket. I wouldn't care if passivate does not work but after trying to use the bean later I get another exception that it can't be activated.
What would be a better way to handle this? Either not to allow jboss to passivate it (how?) or handling the connection somewhere else (where)? Connection pooling is not possible because exactly this (telnet) connection must be used.
Thanks again for your help,
Eddie -
4. Re: Problem with WrappedConnection
davidjencks May 21, 2003 8:24 PM (in response to eddie07)Having a socket in an ejb is a pretty bad idea IMO, and you are finding out some of the reasons why.
How about using an mbean to manage the socket? It's a singleton and doesn't get passivated.