• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JDBC Pool and java Daemon

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But that is a javax.jms.Connection and not a java.sql.Connection. Now I am confused.
 
Hari adya
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic