In my struts.xml file, I have two actions, each of them maps to the *SAME* Action class but two different methods. And these two methods don't call each other. e.g. I have a "/getInventory" action link that maps to "getInventory()" method and "/getInvoice" action that maps to "getInvoice()" method of the same Action class "Order". In the "Order" class there is a "prepare" method.
Questions:
1. On my web app, when I click a link of "get inventory", it calls "/getInventory" and thus triggers the "getInventory()" method. I assume that at this time JVM instantiates an instance of "Order" class, right ? Now, there is another link of "getInvoice", when I click this link, it triggers "getInvoice()" method, does JVM instantiate a *separate* instance of "Order" class ? Or does it use the same instance that was created when I clicked "/getInventory" link ?
I want to know if "var1" is thread safe. I know in servlet, usually class variable is not thread-safe. How about in struts 2's action class ? For servlet it uses one instance multithread model, how about struts 2 action class ? For each action that appears in the struts xml config file, does JVM automatically generates a new action class instance each time an action link is clicked ? or does it behave the way as servlet which is to create a new thread ? If it behaves like servlet then I better not use any class variables.
I can't find accurate answers myself. ANy help will be appreciated.
So, since struts 2 always creates a new instance per request, each time whenit creates a new instance, it calls its prepare() method, and re-initialize its class variables. And these class variables will never be messed up with each other as they belong to different objects. Cool stuff !
Thanks.