• Post Reply Bookmark Topic Watch Topic
  • New Topic

Thread Safety for request.getParameter()  RSS feed

 
sylvia greene
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • 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
 
Bhushan Damle
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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.
 
Sally Mohamed AbdelRahman
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can get all the parameters of the same name by using the method getParameterValues().
 
Saket Barve
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for helping
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!