aspose file tools*
The moose likes JSP and the fly likes session mix up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "session mix up " Watch "session mix up " New topic
Author

session mix up

samar hasan
Greenhorn

Joined: Jun 30, 2009
Posts: 7
i have a web application running on oracle 9i database and tomcat 5 with jdk 1.4. everything was doing fine until the # of users using the application increased (about 300 users) sessions started mixing. so i used single thread model in my servlets . sessions sttopped mixing but the application (at the peak hour) is very slow. could someone please tell me what to do? i want to get rid of the single threadmodel and keep my sessions away from mixing. does changing to another application server help? JBOSS or tomcat 6??? is there is something wrong with my code??? F1 help help
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

is there is something wrong with my code???

Most likely.
samar hasan
Greenhorn

Joined: Jun 30, 2009
Posts: 7
here is a sample of my code

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags.
samar hasan
Greenhorn

Joined: Jun 30, 2009
Posts: 7
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

There is only one instance of each servlet instantiated for each servlet in an application: having non-thread local, non-synchronized instance variables is a complete non-starter.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Do you really not indent your code?
samar hasan
Greenhorn

Joined: Jun 30, 2009
Posts: 7
I do indent my code!!!

So what's the problem??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

David Newton wrote:There is only one instance of each servlet instantiated for each servlet in an application: having non-thread local, non-synchronized instance variables is a complete non-starter.

The code above is not indented; don't be surprised if I ask if you indent your code.
samar hasan
Greenhorn

Joined: Jun 30, 2009
Posts: 7
sorry if it sounds stupid. but i didn't understand what does that mean !!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You're putting the request, response, and session into instance variables. There is only one instance of the servlet. So *every single request* is using the *same* request, response, and session values: overwriting them, reading from them, etc.

See here for more information; this is very basic Java web app stuff. There are a lot of other resources on the web covering this topic, this just happens to be among the first I found on Sun's website.
samar hasan
Greenhorn

Joined: Jun 30, 2009
Posts: 7
but why did this problem appeared when the number of users increased???
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Because before there were more users you were lucky and/or didn't notice.
samar hasan
Greenhorn

Joined: Jun 30, 2009
Posts: 7
Thank you David
Max Rahder
Ranch Hand

Joined: Nov 06, 2000
Posts: 177
Samar: As a rule, never code instance fields in servlets. Furthermore, with servlets (and any kind of programming) you should not use an instance field as a way of "passing" data. I.e., don't have routine A place something in an instance field because you're about to call method B, which needs that value. Instead, simply pass the value to B as a parameter. In your code, pass the request object to performTask(). (And it should pass the request to any routines it calls that need it.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session mix up