File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes JDBC Pool and java Daemon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC Pool and java Daemon" Watch "JDBC Pool and java Daemon" New topic
Author

JDBC Pool and java Daemon

Hari adya
Greenhorn

Joined: Aug 21, 2009
Posts: 10
Hi,

I search the net and the forums, i didnt find an answer.

I want to run a Java Daemon (POJO) on Oracle server's JVM. This daemon initializes a connection pool and gives a connection when another POJO asks for it.
I have been struggling to implement this. Can someone please help me out here?

Thanks,
hari
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'm not sure why you're implementing a Connection Pool, is there a problem with these POJOs getting a Connnection directly from the database?
Hari adya
Greenhorn

Joined: Aug 21, 2009
Posts: 10
Hi David,

There is absolutely no problem getting a connection and connecting to the database.

What I am trying to implement here is,

Normal way of doing it
---------------------------

ConnectionFactory.java : returns a connection
Invoker.java: Consumes the connection

All the java classes run on JVM ( not using any server here, no container managed objects)
So, everytime I invoke Invoker.java, an object of ConnectionFactory.java is created and inturn takes 2-3s to return a connection object.

I want to optimize, hence

What i want to do
--------------------

make ConnectionFactory.java a daemon (or like a service), so that everytime Invoker.java wants a connection, it gets it from ConnectionFactory readily.

Hope I am clear here David.

One more point, if I was using a server here like say Glassfish, then I can just create a DS and pool the connections, but that is not the case here.

Thanks,
Hari
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

firstly if there isn't a problem with the wait or even with the client holding a Connection open, then you don't need to change anything.
It is not clear whether you need to supply Connections for a remote or locally running clients.
If it is local then you can get an existing pooling implementation like DBCP and configure that in service.
If the clients or connection consumers are remote then you will be looking at implementing your own DB agnostic Type-2 or 3 Database Driver and there could be existing implementations of this available too.
Hari adya
Greenhorn

Joined: Aug 21, 2009
Posts: 10
firstly if there isn't a problem with the wait or even with the client holding a Connection open, then you don't need to change anything.
-- yes, you are right this works, but it doesn't have service or daemon that gives out connection objects whenever ConnectionFactory is asked to give one. The JVm creates an object of connectionFactory, loads the driver, creates the connection and then gives a conneciton object. I call ConnectionFactory say atleast 10,000 times a day. Hence I want to make it a daemon
.

It is not clear whether you need to supply Connections for a remote or locally running clients.
--local

If it is local then you can get an existing pooling implementation like DBCP and configure that in service.
--can you please elaborate on the service part? This JVM runs on UNIX

If the clients or connection consumers are remote then you will be looking at implementing your own DB agnostic Type-2 or 3 Database Driver and there could be existing implementations of this available too.


Thanks,
Hari
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

But that is a javax.jms.Connection and not a java.sql.Connection. Now I am confused.
Hari adya
Greenhorn

Joined: Aug 21, 2009
Posts: 10
David, the forum's application automatically put a hyperlink to ConnectionFactory, and I am not talking about JMS here, I am talking about java.sql.connection
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Oops, I wrote that auto linking
You shouldn't need to write any code, but I'm still confused about one part:
Why don't you open a single connection and synchronise access to that single Connection? I just think this since a Connection Pool will open one or more Connections and keep them open anyway. If there will be Connections kept open and you can get away with only using one Connection at a time, write your code to use it like that.

Otherwise, have a look at the dbcp.apache.com, and if you want to register a DataSource in JNDI too then you can use fscontext which is available with the JNDI code from the Oracle site.
fscontext provides the DataSource and required plumbing, register the DBCP pool with fscontext, talk to JNDI and get a Connection.
Hari adya
Greenhorn

Joined: Aug 21, 2009
Posts: 10
Hi David,

Hmm, I ll look into the DBCP, will do some research on it and draw a conclusion.

Ok, lemme give you the complete picture here.

My Java code runs on Oracle 9i's JVM . There is a PL/SQL procedure that calls the 2 Java classes I mentioned.

So, PLSQL procedure-->call java--> object gets created on Oracle's JVM-->code runs-->object returned.

this process runs everytime the class is called. Hence I need a daemon.

one question David, is DBCP managed by a container?

Thanks a lot for your help David,

Regards,
Hari
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC Pool and java Daemon
 
Similar Threads
Clarification
garbage collection and statement closing question
enterprise application with many users
how to use JDBC Connection Pools in a standalone application?
Db connection in a process