多个请求处理 servlet

发布于 2024-12-29 03:27:38 字数 151 浏览 0 评论 0原文

事实: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩世 2025-01-05 03:27:38

事实:servlet 容器为每个 servlet 创建一个实例(希望我在这一事实上是正确的)

不保证,但通常是正确的。所以更多的是假设而不是事实。

如果假设向同一个 servlet 发送 2 个请求来更新表 Y 中同一记录的 x 列,一个请求发送的值是否会被其他请求覆盖?这是如何处理的,容器会自己处理它吗?

这取决于数据库,而不是 servlet 容器。将有两个线程使用同一个 servlet 实例,每个线程都有自己的数据库连接。

但是,当然,第二个请求将覆盖第一个请求放在那里的数据库值。不知道您还希望它如何发挥作用。

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.

神回复 2025-01-05 03:27:38

有 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文