为每个请求创建的单例对象(Singleton Object created for each request)

编程入门 行业动态 更新时间:2024-10-23 17:34:49
为每个请求创建的单例对象(Singleton Object created for each request)

我想创建一个sinlgetom对象,其范围基本上只是request.this将被用来收集错误,我们需要发送错误,当我们发送回应回来..我可以amyone提供指向这个东西? 我也在用春天。

我尝试过使用Spring容器单例对象作用域会话或请求,但仍然mu对象持有较早请求的值

我正在使用AspectJ ..这个错误对象,这可能会导致静态绑定的问题

i want to create a sinlgetom object whose scope is basically only the request.this will be used to collect the errors and we need to send error when ever we send response back.. can i amyone provide pointers toward this thing? i am also using spring.

i tried using Spring container singleton object scope session or request but still mu object is holding values from the earlier request

i am using this error object with AspectJ..is that may cause problem on static binding

最满意答案

我不确定这个单例是否是你想要的 - 如果两个请求同时到达,它们将共享单例对象,并且它们的错误会混淆起来。

是否有可能创建一个对象来保存错误并将其放入一个ThreadLocal对象中。 该对象的范围将受到该请求的约束,并且可以在应用程序内轻松实现对ThreadLocal对象的访问,而无需将引用传递给该对象。

I'm not sure that singleton is what you want here - if two requests arrived concurrently they would share the singleton object, and their errors will get mixed up.

Is it possible to create an object to hold the errors and put that in to a ThreadLocal object. The scope of the object will be constrained by the request, and access to it in the ThreadLocal object is easily achieved from within your application without having to pass a refernce to the object around.

更多推荐

本文发布于:2023-08-02 18:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1380677.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   Singleton   Object   created   request

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!