File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Synchronization problem with session?! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Synchronization problem with session?!" Watch "Synchronization problem with session?!" New topic
Author

Synchronization problem with session?!

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
When a user is logging into the system, I store his userID in a hashtable, together with the companyID. After that I put this hashtable in a session. Is there any synchronization problems about that?

//When logging in I store the user information in a session
int userID = 11;
int companyID = 234;
Hashtable hash = new Hashtable();
hash.put("userID", Integer.toString( userID ) );
hash.put("companyID", Integer.toString( companyID ) );

session.setAttribute("id", hash );

//On each JSP page I recieve the customer information like this
Hashtable hash = ( java.util.Hashtable ) session.getAttribute("id");
int compID = Integer.parseInt( ( String ) hash.get("companyID") );
int custID = Integer.parseInt( ( String ) hash.get("userID") );

Is there any synchronization problems in this way, if several users is log into the system the same time?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
Is there any synchronization problems in this way, if several users is log into the system the same time?

Each instance of session is unique to the user so there is no synchronization problem as long as you don't try to share a session between users. Thats the whole idea with sessions.
The only synchronization problem you might have with sessions would occur if the same user has several requests being processed at the same time.
Bill


Java Resources at www.wbrogden.com
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Yes I have synchronization problems with this way to do it. The customer claims that when they log into the system, they sometimes is accessing another users account. I have seen screendumps, and I believe that this is really happen, not all the time, but sometimes (1 time out of 20). That is a FATAL error!

In my login servlet I SELECT the userID, companyID etc. WHERE username and password is the same as typed in the login form.

Then I store the userID, companyID in a hashtable, and then store the hashtable in a session. All this is done in a servlet, but nothing is synchronized.

// in the login servlet
Hashtable hash = new Hashtable();
hash.put("userID", Integer.toString( userID ) );
HttpSession session = request.getSession( true );
session.setAttribute("userInfo", hash );
...

Then whenever a user is requesting a JSP page, I get this hashtable from the session, and do the SELECT queries...

//INCLUDED JSP PAGE REQUEST
java.util.Hashtable id = ( java.util.Hashtable ) session.getAttribute("userInfo");
int userID = Integer.parseInt( ( String ) id.get("userID") );
...
//Then I do the select queries with this userID

What can go wrong here?

[ December 01, 2005: Message edited by: Jeppe Fjord ]
[ December 01, 2005: Message edited by: Jeppe Fjord ]
Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
After the customer changed the PROXY settings, it works perfect. It seems that the used PROXY setup did some kind of cache problem, which causes the session problem and the sites wasn�t updated after calling a servlet?

How can I avoid this problem if the customer switch on the PROXY settings again? Is it possible to either delete the cache before every request without deleting the session values? Or maybe make a client browser check to test if the cache is enabled before the user is allowed to login? Or what should you do to prevent this session/cache problem?
[ December 02, 2005: Message edited by: Jeppe Fjord ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronization problem with session?!
 
Similar Threads
help with a sql statement
Instance variables
Character handling
Memory leak - Buffer size problem?
Hashtable - SQL Like operation