-
1. Re: Keep the connection alive after a management bean method
peterj Nov 17, 2008 5:07 PM (in response to wimxa)JBossAS maintains a connection pool. Opening a connection really means being given an available, existing, connection from the pool. Closing a connection really means freeing up the connection and placing it back into the pool. Thus, re-opening a connection is not really a big deal.
Note that the physical connections a established lazily - the first request for a connection will establish the minimum number of connections which are placed into the pool. -
2. Re: Keep the connection alive after a management bean method
wimxa Nov 17, 2008 5:31 PM (in response to wimxa)Peter, thanks for the comment.
The problem is not that I close the connection, but JBoss does that even though I don't want it to be closed. At the end, I cannot have a connection live after the method exits. I need that to avoid costly initialization of the legacy code and there is really no other way I see except keeping the connection alive.
Is there a way to tell JBoss (it's CachedConnectionManager, as the below stacktrace says) not to close my connections and that I will take care of that somehow? -
3. Re: Keep the connection alive after a management bean method
peterj Nov 17, 2008 5:47 PM (in response to wimxa)Are you saying that if the connection is released back to the pool that the next time you ask for it you have to go through the initialization again?
You mentioned management bean. Is that a JMX mbean?
As far as I know, if you use a data source, once the user's request completes (and the response is sent), JBossAS will forcibly return the connection to the pool and give you that warning message.
However, if you work directly with the JDBC driver then you can keep the connection open, and it is your responsibility to manage that connection. Note that this mechanism does not work if you are relying on annotations or similar features whereby JBossAS manages transactions for you. For example, this will not work for EJBs. -
4. Re: Keep the connection alive after a management bean method
wimxa Nov 17, 2008 6:02 PM (in response to wimxa)Peter, here is the pseudo-snippet that should answer your questions about how the things are right now:
@Service(objectName = "MyServer:service=MyManagement")
@Management(MyManagement.class)
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public class MyManagementBean implements MyManagement {
@Resource(mappedName = "java:/MY_DATA_SOURCE")
private DataSource dataSource;
private LegacyClass legacyObject;
public void doSomething() {
Connection dbConnection = dataSource.getConnection();
if(this.legacyObject == null || dbConnection.isClosed()) {
this.legacyObject = new LegacyClass(dbConnection, ...);
}
legacyObject.legacyDoSomething();
// ...
// I don't close the connection
}
// ...
}
I get the message in question after doSomething exits. If I understood you correctly, this is not a good way, since I am using a DataSource, correct? I.e. the only option is not using DataSources, but JDBC directly. JBoss will always forcibly close the connection. Is there some parameter that I can tweak this with?
If this is not possible, is there a simple way to get the parameters of that DataSource, so I can use them to make the connection myself? I would like to avoid storing the username, password, URL, etc. in my code directly.
Thanks again for your help! -
5. Re: Keep the connection alive after a management bean method
peterj Nov 17, 2008 6:12 PM (in response to wimxa)Is there some parameter that I can tweak this with?
None that I know of.
[copy]is there a simple way to get the parameters of that DataSource,[/copy]
You can always place a properties file containing the database info into the server/xxx/conf directory, and access it using the jboss.server.config.url system property. Something like this:
String confdir = System.getProperties("jboss.server.config.url");
FileInputStream fis = new FileInputStream(confdir + "somedb.properties");
Properties dbprop = new Properties();
dbprop.load(fis); -
6. Re: Keep the connection alive after a management bean method
vickyk Nov 18, 2008 12:37 AM (in response to wimxa)"wimxa" wrote:
I.e. the only option is not using DataSources, but JDBC directly. JBoss will always forcibly close the connection. Is there some parameter that I can tweak this with?
The CachedConnectionInterceptor(CCI) in the Interceptor that checks for the leaked connections in ejb method calls.You can disable the CachedConnectionInterceptor but I would not recommend you that, I would rather advice you to refactor the LegacyObject, you should not pass the connection object to the LegacyObject.
The DataSource object should be passed to the LegacyObject instead of the connection object.
Check for the CCI at $JBOSS_HOME/server//conf/standardjboss.xml, just uncomment it in the appropriate container.
http://www.jboss.org/community/docs/DOC-12682 -
7. Re: Keep the connection alive after a management bean method
wimxa Nov 18, 2008 9:00 AM (in response to wimxa)Peter, OK, I might do something like that. Thanks!
vickyk, that would mean that all DataSources would behave like this. The last chapter in the link you gave (Turning off Connection Close Checking) is a setup for the whole CachedConnectionManager MBean. Is there a way to do that on a per-DataSource basis? -
8. Re: Keep the connection alive after a management bean method
vickyk Nov 18, 2008 10:36 AM (in response to wimxa)"wimxa" wrote:
vickyk, that would mean that all DataSources would behave like this. The last chapter in the link you gave (Turning off Connection Close Checking) is a setup for the whole CachedConnectionManager MBean. Is there a way to do that on a per-DataSource basis?
No, you can configure the EJB container without out the CachedConnectionInterceptor and tie it to specific EJB where you don't want the connections to be automatically closed... This is a *HACK* , refractor the LegacyObject as explained before.
I am not telling you to play with CachedConnectionManager. -
9. Re: Keep the connection alive after a management bean method
wimxa Nov 18, 2008 10:42 AM (in response to wimxa)No, you can configure the EJB container without out the CachedConnectionInterceptor and tie it to specific EJB where you don't want the connections to be automatically closed... This is a *HACK* , refractor the LegacyObject as explained before.
I am not telling you to play with CachedConnectionManager.
It's not named LegacyObject for nothing - if I could refactor it, I would. OK, bad water here, I'll get out of here and try something else. Thanks for the explanation!