• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What to do to make this web page thread safe?

 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Folks,

I'm trying to write a jsp that invloves the insertion , updation etc of a set of records. Right now , I'm just trying to insert a set of records after selecting values from the dropdown and then inserting them.The thing is that I'm able to get the page to work perfectly when I use it with a single user , however when multiple users try to insert simultaneously , the values of each other.
Below, are my code snippets.

The usage of scriptlets at that point was unavoidable ,due to a few external circumstances. I understand that their usage is not encouraged.And below is how I process my request in the servlet
Servlet.

I just dont seem to understand why the values are being overwritten . Any pointers would be helpful.

And Sorry for the long post!! .I really cant figure out where I 'm going wrong and hence the lengthy post!
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

JSP's are not thread safe by default. To make them thread safe they have to implement SingleThreadModel.

Add isThreadSafe attribute to your JSPs as below.



Cheers,
Raj.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now THAT was really bad advice, ignore it.

JSP can be Thread safe with respect to multiple requests by careful design.

If multiple users are seeing each other's values, it suggests your servlets or jsp are using instance variables instead of good practice.

Bill
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raj Kamal wrote:
JSP's are not thread safe by default. To make them thread safe they have to implement SingleThreadModel.

Wow! Really bad Advice! Do not do this! Ever.

It is unlikely that the JSP is a source of the problems. More likely (as William pointed out) improper variable use is the likely culprit.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, scriptlets are always avoidable with proper structure and planning.

The use of the <%! %> style of scriptlet (which does not appear to be being used here) is also a likely culprit for introducing threading issues.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65122
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And one more piece of advice: using uppercase in HTML makes it really hard to read and sort of went out of vogue in 1998. I'd suggest using lowercase for HTML as if you were using XHTML (even if you aren't). It looks more modern and is more readable.
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You didn't say what data was being misdirected. There could be all kinds of things happening. For example somebody might have used static variables in the Consumer class. Or any number of other things. So knowing what data was the problem is an important clue for you.
 
Vic Hood
Ranch Hand
Posts: 477
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for all the noise folks!Bad ,bad instance variables !
Thanks for the advice !
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry folks...

For the suggestion (if it was a bad one and there seems to be a large number of experts agreeing it was a BAD one).

I thought this was the way to make JSPs Threadsafe. Below are a few sites I found when I ran a quick google:

Webpage #1
Webpage #2
Webpage #3
Webpage #4
Webpage #5

I do not wish to argue but it was the way I was doing things till now as well...

Well one more to 'un-learn'.



Cheers,
Raj.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic