• 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:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Thread Safety for request.getParameter()

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have a form with some text fields. This form is submitted to a JSP page where i do

String n = request.getParameter("name");
.......

and then insert to values in the database.

i want to know is the whole thing Thread safe. Is there a possibilty that another clients values can override the values or the same client can open 2 browser windows and the values may get corrupted.

Thanks
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When u will be opening two browser windows on same client, there will not be any problem as the timespan will be there may be of nanoseconds. But, the first request will be fulfilled first & then the next.
But, when it will be running on multiple clients, it may happen that two or more requests come to the servlet/jsp at one and the same time. Here, the problem occurs. And as a solution you will have to use keywordSynchronized in your method.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSPs are not thread safe unless you make them. For you to ensure that the page is thread-safe, you need to use the directive:

this says that you as the developer have not checked that the jsp is thread-safe, and specifies that the jsp engine will ensure that your jsp's generated servlet will handle each request on its own without overwriting of parameter values.
 
Sheriff
Posts: 67759
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
Your question actually has nothing to do with the thread safety of the getParameter call or of your JSP. There will be no thread safety isssues.

What you are really asking about is database contention. Most databases I know will easily handle the situation you describe by locking the record while the first write is being performed and blocking the secod write until it is finished.

As to two users over-writing each others values --- that's a different issue (not a thread safety issue) that you might want to poke around in the JDBC forum about.
 
sylvia greene
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying.

isn't there a chance of one user's parameter overwriting another user's paramter.

User1 does
String s = request.getParameter("s");


User2 does
String s = request.getParameter("s");


Is there a possiblility that user2's value overwrites the user1's value.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can get all the parameters of the same name by using the method getParameterValues().
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


isn't there a chance of one user's parameter overwriting another user's paramter.

User1 does
String s = request.getParameter("s");
User2 does
String s = request.getParameter("s");

Is there a possiblility that user2's value overwrites the user1's value.



Sylvia,

In the example above, you are merely fetching the value. The question for overwriting does not arise at all here.

If you mean that the two users try to update the values fetched simultaneously, then as Bear mentioned above that becomes a database issue, appropriate for the JDBC forum.

Regards,
Saket
 
Bear Bibeault
Sheriff
Posts: 67759
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

Is there a possiblility that user2's value overwrites the user1's value



No. Each of these variables is local to the method created for the JSP.
 
sylvia greene
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for helping
 
It runs on an internal combustion engine. This ad does not:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic