File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Interesting session exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Interesting session exception" Watch "Interesting session exception" New topic

Interesting session exception


Joined: Sep 22, 2005
Posts: 11
Dear sirs,

I am getting some interesting Session scope Exception..
I am using the technology Struts, EJB with JBoss
I am using Session Facade and Service Locator as desin pattern
Now the scenario is given below,

I am requesting for a collection of Entity Bean by passing the request as given below,

Action Class -> Session Bean (Stateless) -> Service Locator -> Entity Bean(CMP)

I am extending my action class with org.apache.struts.actions.DispatchAction

When two users of different sessions are logging in to the application and accessing the same collection; only one user is getting the Collection.
I tried to print the session ID ob each users at the console. Before the request is made the session id of each user is different as given below,

User 1 : 257B112049648471974498E34F9B1EDC
User 2 : A674D5852CB31EA975929E833E5C90B4

But after getting the collection from the bean; when i printedthe session ID along with the Collection size; the console is printing the same session for both request as given below,

1. showMessage positionMap.size()==> 124 <=> Session Id A674D5852CB31EA975929E833E5C90B4
2. showMessage positionMap.size()==> 124 <=> Session Id A674D5852CB31EA975929E833E5C90B4

This means that the user with session "257B112049648471974498E34F9B1EDC" is not getting the collection. This problem is occuring when both users are requesting for the same collection simultaneously, I checked the beam part and service locator part. I think they are working fine.

The ServiceLocator Code is given below...

public class ServiceLocator implements ServiceNames{

private static ServiceLocator serviceLocator = null;
private static Hashtable<String,Object> ejbHomeCache = null;
private static Hashtable<String,DataSource> dataBaseCache = null;

serviceLocator = new ServiceLocator();

private ServiceLocator(){
ejbHomeCache = new Hashtable<String,Object>();
dataBaseCache = new Hashtable<String,DataSource>();

public static ServiceLocator getInstance(){
return serviceLocator;

private static EJBHome getEJBHome(String serviceName, Class ejbHomeClass){

EJBHome ejbHome = null;
System.out.println("%%%%%%%%%%%%%%%%%%%%%% from ejbHomeCache Remote HashTable");
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.URL_PKG_PREFIXES, "org.jnp.interfaces");
properties.put(Context.PROVIDER_URL, "jnp://localhost:1099");
InitialContext ctx = new InitialContext(properties);
Context ctx = new InitialContext();
Object jndiRef = ctx.lookup(serviceName);
Object objRef = PortableRemoteObject.narrow(jndiRef,ejbHomeClass);
ejbHomeCache.put(serviceName, objRef);
return ((EJBHome)objRef);
}catch(Exception e){
System.out.println("Error in getRemoteEJBHome()-Remote in finding Remote EJBHome ");
return null;

private static EJBLocalHome getEJBHome(String serviceName){

EJBLocalHome ejbHome = null;
System.out.println("%%%%%%%%%%%%%%%%%%%%%% from ejbHomeCache HashTable");
Context ctx = new InitialContext();
Object objRef = (EJBLocalHome)ctx.lookup(serviceName);
return ((EJBLocalHome)objRef);

}catch(Exception e){
System.out.println("Error in getEJBHome()-Local in finding Remote EJBHome ");
return null;

public static ImportsVzaHeaderLocalHome getVzaHeaderLocalHome(){
ImportsVzaHeaderLocalHome vzaHeaderHome = null;
vzaHeaderHome = (ImportsVzaHeaderLocalHome)getEJBHome(VZAHeaderLocal);
}catch(Exception e){
System.out.println("From ServiceLocator's getVzaHeaderHome method Exception in finding the VzaHeaderHome ");
return vzaHeaderHome;
/************************************END Of ServiceLocator *************************************************************/

Your help and suggestions solicited..
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

You've been warned numerous times, and so now I'm blocking your account from making further posts until you comply with our naming policy by going
and editing your display name to conform to the required "Firstname Lastname" format. You can send email or a private message to me to have your account reinstated once you've complied.

By the way -- I just deleted two duplicate copies of this message. Please Carefully Choose One Forum for your posts. Thanks.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Interesting session exception
jQuery in Action, 3rd edition