Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is javax.sql.DataSource a costlier resource like java.sql.Connection?

 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author
Saloon Keeper
Posts: 4031
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A DataSource is a method for obtaining a Connection, often with JNDI.
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21546
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then why don't you explain what that means and why you think it?
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, i did not get what do you mean still?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35266
383
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ilias,
A datasource often represents multiple connections (a connection pool.) It is caching at a higher level.
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So does that means - if i create an instance to the DataSource i am actually creating a new connection pool?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
ilias basha
Ranch Hand
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jaikiran Pai
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic