• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

What is the best way to share database connection pool?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My environment does not include any application servers or web servers, just a plain JRE.
 
Ranch Hand
Posts: 251
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Phile: I have more than one JVM running. Each application runs as a standalone server.
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Sun's recommended solution is to use the JDBC2.0 DataSource facility that supports database connection pooling.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
I think I'll just lie down here for a second. And ponder this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic