Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

JNDI design question

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get the connection using weblogic server 6.0 datasource. For my Jndi context i always use same credential and other parameters as required to create InitialContext object. Should I declare DataSource object as static variable in my class or instanace variable.
Is JNDI lookup for each http request is expensive.
If i design a singleton class that use same DataSource object for all the simultaneous clients. Is it save to do that or i should not use singleton pattern that creates a single DataSource Instance? In other words i should create a new DataSource object for each request to get connection?
Note : I am also using the connection pooling so i always return connection after executing my query?
// Is is to save to use same datasource object when Datasource object is shared among the concurrent clients
public class ServiceLocator{
private DataSource ds;
private static ServiceLocator sl;
public static getInstance(){
if (sl == null){
sl = new ServiceLocator();
}
return sl;
}
private ServiceLocator(){
try {
Context ctx = new InitialContext(ht);
ds = (javax.sql.DataSource) ctx.lookup ("myJtsDataSource");
} catch (NamingException e) { }
}
public Connection getConnection(){
return ds.getConnection();
}
[This message has been edited by Nasim Sohail (edited September 13, 2001).]
[This message has been edited by Nasim Sohail (edited September 13, 2001).]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi There i am looking for exactly the same answers.Pls let me know if you come to know something at mailto:mahendragoyal@yahoo.com
------------------
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not neccessary to do DataSource as, static if you want to perform connection pooling.
Yes, JNDI lookup for each request is expensive, but it is not needed beacause your class is singalton & only one instance is created & you will lookup DataSource in Constructor so it is lookup only once.
Then you maintain a pool of connections & populate and maintain it.
Obviously, In this senario DataSource object is shared between different clients but the method which return connection should be synchronized.
Here are also some delay can be produce if multiple client are reached at the same time, but i think it
is less than to lookup the DataSource object each time. You could not return multiple connection at the
same time beacuase multithreading is not allowed in ejb.
CMP approach is much better then this, beacuse server handle all these pooling issues itself.
In your code getInstance() not returning any value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!