Concurrent access null session/application objects

B

Ben

I'm building a web application using Servlets/JSP and Tomcat 5.0 and
I'm using HttpServletRequest.getSession() and
ServletConfig.getServletContext() to store session and application
scope objects. The current design has non-servlet classes accessing the
objects through the servlet's get/set methods. The application
generates WML so I'm not using Struts or similar framework.

Things seem to work fine when accessing the server from a single
client. The problem is when accessing the server concurrently from
multiple clients, getSession() and getServletContext() sometimes return
null (or the object being retrieved through getAttribute() is null).
This does not always happen and I can't find any discernable pattern.

Does anyone have any idea why this might be happening or what can be
done to make the application more stable for multiple users? Thanks.

Ben
 
R

Robert

You cannot share objects across user sessions. That is by design.
Each time you hit a web server from a different client that client
creates their own session. The servlet context should always work
though that's peculiar. I think you usually get the servletContext
from the session object. That should be the same from client to
client. Also if you want another way to make an object accessible
"globally" try a singleton. These guys have a good article on some
singleton pitfalls.

http://www-106.ibm.com/developerworks/java/library/j-dcl.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top