Reputation: 5654
fact : servlet container creates one instance per servlet(hope i am correct on this fact)
quest: if suppose 2 requests are sent to the same servlet to update the x column in table Y for same record
will the value sent by one request is going to be overriden by other request ?
how this is handled, will the container is going to handle it by itself or ?
please reply
Upvotes: 1
Views: 2178
Reputation: 403441
fact : servlet container creates one instance per servlet(hope i am correct on this fact)
Not guaranteed, but usually true. So more an assumption than a fact.
if suppose 2 requests are sent to the same servlet to update the x column in table Y for same record will the value sent by one request is going to be overriden by other request ? how this is handled, will the container is going to handle it by itself?
This is up to the database, not the servlet container. There will be two threads using the same servlet instance, each with their own database connection.
But yes of course, the second request will overwrite the database value put there by the first request. Not sure how else you'd expect this to work.
Upvotes: 1
Reputation: 54074
There is 1 servlet instance. Correct.
But the request will be handled by different threads created by the container.
So the servlet code will be called by 2 different threads.
So make sure your code is thread safe
Upvotes: 0