This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
A servlet only has one instances in the server, but it will create a new thread to handle every new request.
Joined: Jun 20, 2005
That's true. As the struts controller (ActionServlet is actually a servlet) and it tries to re-use instances of existing components (actionforms, action classes etc). Keeping this in mind, just want to know how many action instances will be craeted if we have mupltiple action mappings for the same action (mywebapp.actions.ManageCustomerAction) ?
How many action form instances will be created if we have multiple action form mappings for the same action form(mywebapp.forms.CustomerForm) ?
There's an action created per action mapping (if I'm remembering correctly). This is trivial to verify by simply logging action creations. ActionForms are only re-used if they're session-scoped, otherwise there's an instance created per request.
Why do you want to know?
Joined: Jun 20, 2005
This is trivial to verify by simply logging action creations.
Should I create public constructor of my action and write log statements in it for this ?
ActionForms are only re-used if they're session-scoped, otherwise there's an instance created per request.
What if I have action mappings modified as :
Still will the same instance of CustomerForm be used for serving both the requests ?
Just want to resolve the puzzle around singleton behaviour of action instances. If they are truely singleton or not ?
Action instance is single per application per Action.only one instance of any action class is created.
That are actually maintained in HashMap named "actions" which is instance variable of RequestProcessor class. and only one instance of request processor is created per application per module.
In hashmap key is full path of Class value is instance of action class.
every time before creation action first struts framework will check it is in hashmap or not, if it is there it is reused else newly created and put it in hashmap.
mapping is not considered for putting data in hashmap hence I think only one instance of action class will be created.