开发者

how does tomcat like web container handle struts 2 variables?

i am a newbie . i have a question regarding struts 2 framework and tomcat . i know that each request has it own thread , but my question is are the global variables defined in struts action shared amongst requests. for ex: if i have a global variable named say int pageNo; and i am using in say method called paginationAll() can i use the same variable (pageNo) for another method called say pagi开发者_如何学PythonnatonMaterialAll() in the same action or does each thread has its own set of variables even though globally defined?


In Struts 1 it wasn't advisable to have globally scoped variables/fields in your action classes - they were shared between all requests.

However, in Struts 2 I believe this has changed - Actions are now constructed for each request.

See:

http://struts.apache.org/2.0.14/docs/comparing-struts-1-and-2.html

Struts 2 Action objects are instantiated for each request, so there are no thread-safety issues. (In practice, servlet containers generate many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.)


Global shared variables don't sound thread safe to me. I'd rethink that design.


YOur question is not very clear, but it this helps: in Struts2 a new instance of the Action object is created for each request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜