• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Connetion pool

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am calling webservices deployed on glassfish. Sometimes I call a webservice that lists data and it returns a null, call it again and it returns data. What could be the cause for that.
Below is my code for the connections. I am using a connection pool set up on glassfish. Are there any flaws in my code? Please assist.

private static InitialContext getContext() throws NamingException{
if(ctx == null)
ctx = new InitialContext();
return ctx;
}

private static DataSource getDataSource(String name) throws NamingException{
if(ctx == null){
DB_connection.getContext();
}
switch(defaultNum){
case MASTER:
if(dsMaster == null){
dsMaster = ds = (DataSource)ctx.lookup(name);
}
break;
case WEB:
if(dsWeb == null){
dsWeb = ds = (DataSource)ctx.lookup(name);
}
break;
case BIG_BLUE:
//Not is use for now
break;
}
return ds;
}
/**
* @return Connection for MasterDB
* @throws SQLException
*/
protected static Connection openMasterDatabase() throws SQLException{
defaultNum = MASTER;
try {
getDataSource(JNDI_MASTER);
if(dsMaster != null){
conn = dsMaster.getConnection();
}
}
catch (NamingException e) {
e.printStackTrace(System.err);
}
return conn;
}

/**
* @return Connection
*/
public static Connection openWebAppsDatabase() throws SQLException{
defaultNum = WEB;
try {
getDataSource(JNDI_WEB);
if(dsWeb != null){
conn = dsWeb.getConnection();
}
}
catch (NamingException e) {
e.printStackTrace(System.err);
}
return conn;
}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You said that the webservice returns null - what does that mean? If that's incorrect, then the web service should be the first line of inquiry.

What does the connection pool have to do with the web service?
 
Patrick Mugabe
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The webservice returns data but in some instances it returns null then when you call it for the second time it returns data which is why I thought it might be the Connection pool.
Another error I just got now is:
Error in allocating a connection. Cause: java.lang.RuntimeException: Got exception during XAResource.start

but this doesn't happen all the time. It's an on off thing.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It has nothing to do with web services.Have you checked that the connection pool is created successfully ? Check with the container documentation on as how to configure the connection pool properly and check the connections.

One more thing to look at would be the containers log files.Might give you some useful information.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic