File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSF and the fly likes Unexpected behavior: Different users sharing session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Unexpected behavior: Different users sharing session" Watch "Unexpected behavior: Different users sharing session" New topic

Unexpected behavior: Different users sharing session

Carlos Conti
Ranch Hand

Joined: Apr 21, 2010
Posts: 131
Hi there,
i have the following issue. When two users access concurrently my application, the managed beans seem to lose their state. I thought this was due to re-initialization of the session managedbeans. So I struggled for a long time to find out for which reason those beans were being reset, and finally found out the problem, the users, although sitting on different computers, are actually sharing the same session id!. So the beans are not being reset automatically, but instead as a result of the application logic itself (when starting a process, I previously set the managedbean's members state to null in order to cleanup resources and prevent malfunction). I found it out by checking the session id value inside a custom PhaseListener, and saw that the two users shared the session object.

So now, on one hand I know what the problem is, but on the other, don't know what actually makes the server manage the creation of a new session. I was 100% sure of the fact that the server would check the origin of requests, and when detecting a new one when comparing with the existing connections, it would create a new session object and bind it to that origin (i.e. IP address?).

So I see myself now involved with the task of manually managing creation and destruction of sessions. And I don't know exactly where to start.
Regarding the problem, does anyone know of a straight solution to the problem? Should I set something in any of the *.xml config files?

Many thanks in advance for your insights.

Carlos Conti
Ranch Hand

Joined: Apr 21, 2010
Posts: 131

I found the error. In fact there was no session sharing. Don't know why I got the same session ids when checking then the day after went through some tests and the session ids were different. Sorry for that.

My problem was that I was not considering that a custom MyPhaseListener was indeed "static", and that instance was holding a key instance of the managed beans, which triggered update methods. That's why one user was overriding the results of another one. Now I store those key instancees in the session, and it has been solved.

Hope nobody brainstruggled with this issue.
I agree. Here's the link:
subject: Unexpected behavior: Different users sharing session
It's not a secret anymore!