views:

50

answers:

3

Is it safe to run a database connection pool (like Commons DBCP or c3p0) as part of an application deployed to an application server like Glassfish or Websphere? Are there any additional steps over a standalone application that should be taken to ensure safety or performance?


Update, clarification of reason - the use case I have in mind could need new data sources to be defined at runtime by skilled end users - changing the data sources is part of the application's functionality, if you like. I don't think I can create abnd use container-managed pools on the fly?

A: 

I don't see why you'd want to. Why not use the connection pool that the app server provides for you?

Update: I don't believe it's possible to create new pools on the fly without having to bounce the app server, but I could be wrong. If that's correct, I don't believe that Commons DBCP or C3P0 will help.

duffymo
I thought someone would ask that - clarified use case in question.
Brabster
What exactly would require recycling AS? Pool is just a set of connections used by specified JDBC driver.
Vladimir Dyuzhev
Of course, but setting up a connection pool requires changes to the app server configuration. If it's only read on start up, and not refreshed periodically, there's no way for the app server to know that its configuration has changed - hence the bounce.
duffymo
Configuration is changeable on the fly using JMX. On-disk config is read on startup, and saved on update or on shutdown.
Vladimir Dyuzhev
+1  A: 

AFAIK it works, but it will of course escape the app. server management features.

Also, I'm not entirely sure how undeployment or redeployment happens and whether the connections are correctly disposed. But that can be considered as a minor safety detail: if disposed improperly, connections will simply time out I guess. I'm also not entirely sure whether it works for XA data source which integrates with the distributed transaction manager.

That said, using the app. server pool is usually a matter of configuring the JNDI name in a configuration file. Then you get monitoring, configuration from the admin console, load management, etc. for free.

ewernli
Dispose is easy: create an unmapped servlet, and dispose all connections in destroy() method. The method is called when app is unloaded.
Vladimir Dyuzhev
Server pool is usually a matter of configuring connection URL, credentials, connection properties, pool sizes, connection validation options, and so on, and so on... and yes, JNDI name :)
Vladimir Dyuzhev
+1  A: 

In fact, you can create container-managed datasources depending on AS you use.

For example, Weblogic has an extensive management API that is used, for example, by their own WLST (Weblogic Shell) to configure servers by scripts. This is, of course, Java API. It has methods to create and configure datasources too.

Another route is JMX-based configuration. All modern AS expose themselves as JMX containers. You can create datasources via JMX too.

All you need is to grant your application admin privileges (i.e. provide with username/password).

The benefit of container-managed DS is it can be clustered. Also, it can be managed by human being using standard AS UI.

If that doesn't work for you, why, sure you can create application-managed DS any time and in any numbers. Just keep in mind that it will be bound to a specific managed server (unless you implement a manual clustering of it's definition).

Vladimir Dyuzhev
BTW, downside of container-managed pool is that is will survive the application. App is gone, so is user, but pool is still there. Do you want it or not -- depends on your app.
Vladimir Dyuzhev
This would require having the rights to do it (and you usually don't want to give such rights to an application).
Pascal Thivent
In WLS you can grant a fine-tuned role (I believe, it's Deployer) to the application. In any case, I myself would create app-managed DS in such a case.
Vladimir Dyuzhev