多个请求处理 servlet
事实:servlet 容器为每个 servlet 创建一个实例(希望我在这一事实上是正确的)
quest:如果假设有 2 个请求发送到同一个 servlet,以更新表 Y 中的 x 列的同一记录 一个请求发送的值会被其他请求覆盖吗? 这是如何处理的,容器将自行处理它还是? 请回复
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不保证,但通常是正确的。所以更多的是假设而不是事实。
这取决于数据库,而不是 servlet 容器。将有两个线程使用同一个 servlet 实例,每个线程都有自己的数据库连接。
但是,当然,第二个请求将覆盖第一个请求放在那里的数据库值。不知道您还希望它如何发挥作用。
Not guaranteed, but usually true. So more an assumption than a fact.
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.
有 1 个 servlet 实例。正确的。
但请求将由容器创建的不同线程处理。
因此 servlet 代码将由 2 个不同的线程调用。
因此请确保您的代码是线程安全
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