• 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

How many JNDI lookup for datasource in websphere

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Question on JNDI lookup for datasource in websphere. My understanding is that if you have configured a connection pool on server like web sphere then the JDNI binding should occur once to initialize the DataSource object. Then later multiple threads can use this single DataSource object and call the getConnection() to get new connection from the pool. Is it correct?

java code below:


private static OLBDataSource instance = null;
private DataSource dataSource = null;

//make sure there is only one instance of OLBDataSource. aali
static {
try {
instance = new OLBDataSource();
} catch (NamingException e) {
instance = null;
}
}


private OLBDataSource() throws NamingException {
try {
Properties params = new Properties();
params.setProperty(Context.INITIAL_CONTEXT_FACTORY, WSN_INITIAL_CONTEXT_FACTORY);

// Look up the datasource configured on the server.
InitialContext context = new javax.naming.InitialContext(params);
dataSource = (DataSource) context.lookup("jdbc/myDB");

}catch


public static DataSource getMyConnection(){
return dataSource;
}


//Now multiple threads can call the above getMyConnection() method and then call getConnection() to get unique connection from the thread pool.

Is my understanding correct?

 
On top of spaghetti all covered in cheese, there was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic