I have an app connecting to an EJB to retrieve some data. The EJB is in a separate EAR. The app is using a delegate-singleton pattern to get a connection to the EJB. The problem is, the EJB gets redeployed quite often because it's still being developed and every time this happens my app ends up disconnecting and unable to reconnect when the EJB comes back online because the singleton's getInstance method keeps returning an empty remote object reference and the connection cannot be reestablished, so I have to redeploy my client app to be able to reconnect. Any way to keep this from happening, that doesn't involve doing lookups on every request?
public class Delegate
{
...
private DataStoreService getDataStoreServiceInterface {
ServiceLocator serviceLocator = ServiceLocator.getInstance();
return serviceLocator.getDataStoreService();
}
public Data getData(){
DataStoreService dataStoreService = getDataStoreServiceInterface();
return dataStoreService.getData();
}
}
public class ServiceLocator{
private static ServiceLocator instance = null;
private DataStoreService dataStoreService = null;
protected Context context;
private ServiceLocator(){
context = new InitialContext();
dataStoreService = (DataStoreService)context.lookup(DataStoreService.class.getName());
}
static public ServiceLocator getInstance(){
if (instance == null) {
instance = new ServiceLocator();
}
return instance;
}
}
Apparently this is a container bug in Weblogic 10.3.6, I had to remove singleton logic to avoid this issue