| Author |
Is javax.sql.DataSource a costlier resource like java.sql.Connection?
|
ilias basha
Ranch Hand
Joined: Nov 27, 2008
Posts: 55
|
|
Is javax.sql.DataSource a costlier resource like java.sql.Connection?
I am asking this question, as i have seen one of the code having a SingleTon implementation to get the DataSource object.
|
 |
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3652
|
|
|
A DataSource is a method for obtaining a Connection, often with JNDI.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
ilias basha
Ranch Hand
Joined: Nov 27, 2008
Posts: 55
|
|
But, i have seen one code, where in singleton patten has been applied to get the DataSource instance - this made me to think whether this is a costlier resource as how Connection object?
Otherwise, what could be the reason behind this?
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
Then why don't you explain what that means and why you think it?
|
 |
ilias basha
Ranch Hand
Joined: Nov 27, 2008
Posts: 55
|
|
|
I'm sorry, i did not get what do you mean still?
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26195
|
|
Ilias,
A datasource often represents multiple connections (a connection pool.) It is caching at a higher level.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
ilias basha
Ranch Hand
Joined: Nov 27, 2008
Posts: 55
|
|
|
So does that means - if i create an instance to the DataSource i am actually creating a new connection pool?
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8146
|
|
ilias basha wrote:So does that means - if i create an instance to the DataSource i am actually creating a new connection pool?
Typically, you don't create a datasource instance. You configure a datasource, in a runtime environment, and the datasource is then made available through JNDI. You then get hold of the datasource through a jndi lookup, in your code. And once you have access to that DataSource instance, you call the getConnection() method on it. Internally, the DataSource then returns a connection from the pool of connections it maintains.
|
[My Blog] [JavaRanch Journal]
|
 |
ilias basha
Ranch Hand
Joined: Nov 27, 2008
Posts: 55
|
|
If i am using TOMCAT as container and configured all JNDI configuration with required properties, once TOMCAT is started, the connection pool should be ready and when we lookup for the DataSource instance we will get hold of the connection pool.
Am I correct here?
If i am correct above, even if i try to lookup multiple times, i will get the hold of same connection pool, which is created at the startup of TOMCAT??
Thanks for being patient enough to explain!
|
 |
Jaikiran Pai
Marshal
Joined: Jul 20, 2005
Posts: 8146
|
|
ilias basha wrote:If i am using TOMCAT as container and configured all JNDI configuration with required properties, once TOMCAT is started, the connection pool should be ready and when we lookup for the DataSource instance we will get hold of the connection pool.
Am I correct here?
Yes, that's correct.
ilias basha wrote:
If i am correct above, even if i try to lookup multiple times, i will get the hold of same connection pool, which is created at the startup of TOMCAT??
That's correct.
|
 |
ilias basha
Ranch Hand
Joined: Nov 27, 2008
Posts: 55
|
|
Thanks Jaikiran Pai
|
 |
 |
|
|
subject: Is javax.sql.DataSource a costlier resource like java.sql.Connection?
|
|
|