This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlets basic question 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 » Servlets
Bookmark "Servlets basic question" Watch "Servlets basic question" New topic

Servlets basic question

Mathur Neni
Ranch Hand

Joined: May 10, 2004
Posts: 33
I guess this may be a basic question.

We have a servlet, which has a protected inner class, which contain some attributes. When multiple users are accessing, app is giving wrong info back.

Is there any reason that the attributes in the inner class are being shared when multiple users access. And thus can cause any switched data being displayed to users.

Any suggestions are helpful.

Thanks in advance.
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Access to instance data in servlets needed to be synchonized (whether it's an inner class or a simple primitive). Local (a.k.a. automatic) variables within functions are okay though. So, you might want to try creating your info within the doGet method, or wherever you're doing it.

Mathur Neni
Ranch Hand

Joined: May 10, 2004
Posts: 33
Thanks for the reply.

Is it the same case in struts action classes also. Just I am curious as we are having another scenario like this?

I agree. Here's the link:
subject: Servlets basic question
It's not a secret anymore!