• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

What to do to make this web page thread safe?

 
Ranch Hand
Posts: 477
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 28399
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for all the noise folks!Bad ,bad instance variables !
Thanks for the advice !
 
Rajkamal Pillai
Ranch Hand
Posts: 479
1
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic