views:

52

answers:

3

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 paginatonMaterialAll() in the same action or does each thread has its own set of variables even though globally defined?

+1  A: 

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.)

Jon
A: 

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

leonbloy
+1  A: 

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

duffymo