• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the best way to share database connection pool?

 
LGu Gu
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bunch of separate Java applications running. What is the best way for them to use 1 database connection pool? Thanks!
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hard to give a definitive answer w/out knowing your environment, but this often comes up in a webserver environment. If that is your case you are lucky since most webservers provide a JNDI-lookup capability, and built-in or third-party resource pooling be it JDBC connections, Mail sessions, or whatever.
It may not be useful to launch into too much detail, but in a Tomcat environment you can define a resource and then access it via a JNDI-lookup in the application (Servlet, bean, JSP, etc.)
If you provide a little more information about your runtime environment someone can give you a more detailed answer.
 
LGu Gu
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My environment does not include any application servers or web servers, just a plain JRE.
 
Phil Chuang
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well if all the applications are running in the same JVM, you could use a singleton object to control access to the connection pool.
 
LGu Gu
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Phile: I have more than one JVM running. Each application runs as a standalone server.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Sun's recommended solution is to use the JDBC2.0 DataSource facility that supports database connection pooling.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by L Gu:
Phile: I have more than one JVM running. Each application runs as a standalone server.

Sounds like you should use RMI. You won't be able to pass the connection (they aren't serializable) so you will need to write an app to do the actual db access and pass back a RowSet object (assuming you are doing select statements).
 
LGu Gu
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thomas: First, thanks for you reply. However, If I use the solution you suggested, I have to rewrite all of my applications. So currently, I really want to just have a connection pool shared by all applications, and only replace few lines code on each application. Anybody have a good solution?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic