Forums Register Login

Thread Safety for request.getParameter()

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
you can get all the parameters of the same name by using the method getParameterValues().
+Pie Number of slices to send: Send
 


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
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
Thanks for helping
Just the other day, I was thinking ... about this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1528 times.
Similar Threads
Another simple question
how to get form parameters data to a servlet?
request.getParameter access the Struts form values
JDBC and Servlet
how to retrieve value from autogenerated(oracle sequence) column in a servlet.
showing japanese characters
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 09:41:18.