简体   繁体   English

将HttpServletRequest对象存储在队列中以便以后处理是危险的吗?

[英]Is it dangerous to store HttpServletRequest objects in a queue for later processing?

So, I'm in a situation where I want to queue up a bunch of HttpServletRequest objects for asynchronous processing. 所以,我处在一种情况,我想排队一堆HttpServletRequest对象进行异步处理。 Put aside for the moment whether or not this is a wise strategy -- it actually is in this case, as I'm trying to retrofit an awful legacy system -- is this a dangerous thing to do? 暂时搁置这是否是一个明智的策略 - 实际上就是在这种情况下,因为我正在尝试改造一个糟糕的遗留系统 - 这是一件危险的事情吗?

What I'm concerned about here is whether or not the HttpServletRequest object holds onto any valuable resources or open connections that would lead to deadlocks or resource contention issues. 我在这里关心的是HttpServletRequest对象是否保留任何有价值的资源或打开连接会导致死锁或资源争用问题。

Assume here that I'm implementing a simple servlet with a doPost() method that takes the HttpServletRequest object, puts it into a LinkedBlockingQueue, and then sends the user some kind of stock response (like a 301 redirect to a confirmation page). 这里假设我正在实现一个带有doPost()方法的简单servlet,该方法接受HttpServletRequest对象,将其放入LinkedBlockingQueue,然后向用户发送某种股票响应(如301重定向到确认页面)。

Thank you! 谢谢!

i've seen the internals of jetty, and i can assure you that moving that structure out of the current request would be very, very bad. 我已经看到了码头的内部,我可以向你保证,将这个结构从当前的请求中移出会非常非常糟糕。 there's all kinds of current connection state which cannot be used outside of the current request. 有各种当前连接状态,不能在当前请求之外使用。 i can't help but assume that would be true for pretty much any servlet container. 我不禁想到,几乎任何servlet容器都是如此。

it sounds like you are planning on responding to the original request and then doing some additional processing. 听起来您正计划响应原始请求,然后进行一些额外的处理。 i'd recommend copying the info you need from the original request into a separate data structure for the offline processing. 我建议将原始请求中所需的信息复制到单独的数据结构中以进行离线处理。 also, if you are dealing with code which requires an HttpServeletRequest, you can always mock up your own with the bits of data required by the code. 此外,如果您正在处理需要HttpServeletRequest的代码,您始终可以使用代码所需的数据位来模拟您自己的代码。

I did a very similar thing, and one of the problems I experienced is that Jetty seems to clean up stuff inside the HttpServletRequest at some point, leaving you with null return values from some of the getXYZ methods and even throwing NPEs at you for others. 我做了一个非常相似的事情,我遇到的一个问题是,Jetty似乎在某些时候清理了HttpServletRequest中的内容,让你从某些getXYZ方法中获得null返回值,甚至为其他人抛出NPE。

So, yes, it is dangerous. 所以,是的,这很危险。

I now copy the stuff I need inside doPost and doGet and forget about the instance altogether. 我现在在doPostdoGet复制我需要的东西,完全忘记了这个实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM