Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many JNDI lookup for datasource in websphere

 
khan gul
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic