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
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: 12612
posted
0
Do you really not indent your code?
samar hasan
Greenhorn
Joined: Jun 30, 2009
Posts: 7
posted
0
I do indent my code!!!
So what's the problem??
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
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
posted
0
sorry if it sounds stupid. but i didn't understand what does that mean !!
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
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
posted
0
but why did this problem appeared when the number of users increased???
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12612
posted
0
Because before there were more users you were lucky and/or didn't notice.
samar hasan
Greenhorn
Joined: Jun 30, 2009
Posts: 7
posted
0
Thank you David
Max Rahder
Ranch Hand
Joined: Nov 06, 2000
Posts: 177
posted
0
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.)