If you need to make the same connection pool accessible from multiple
instances of the Java Virtual Machine, then yes, RMI is about the only
solution.

If, however, your connection pool can be unique for each launch of a VM, then
you could solve your problem quite easily with the good old fashioned
Singleton pattern combined with Java's static initializer. (If you are
unfamiliar with the Singleton pattern, buy, read, and memorize "Design
Patterns" by Gamma, et.al. or any other decent book on patterns.)

Something like this:

public class MyApp extends JFrame
{
    private static ConnectionPool connectionPool = ConnectionPool.getPool();
    .....
}

public class ConnectionPool
{
    private static ConnectionPool instance;

    private ConnectionPool()
    {
        // Set up connections
    }

    public static ConnectionPool getPool()
    {
        if (instance == null) instance = new ConnectionPool();
        return instance;
    }
}

Trevor

P.S. In the future, please post questions like these to a JDBC or RMI mailing
list or one of the newsgroups. This list should be reserved for Linux-specific
Java questions.

Ernst de Haan wrote:

> Check out the RMI docs. Especially the part about the Naming service.
> Should answer your question.
>
> If ya have JDK docs installed, check the RMI guide.
>
> Christopher Rowan wrote:
> >
> > Heya Hiya Ho!
> >
> > I want to make a database connection pool class that starts up,
> > preconnects n jdbc connections, then waits to be called by various apps.
> >
> > How do I make Java wait without exiting and without putting it into a
> > cycle sucking loop?
> >
> > I've checked the API docs and a few books (my due dilligence) but can't
> > find an answer.
> >
> > It's got to be ez - I just can't find it.
> >
> > Also, is CORBA/RMI the only way to call the connections?  Is this even
> > possible?
> >
> > Suggestions?
> >
> > Chris Rowan
> > This mail is CopyLeft

Reply via email to