• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

struts 1.X Action vs Actionmappings

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Supoose I have action mappings defined in struts-config.xml as:



If I add a cutomer via /addCustomer.jsp and then update that customer via /editCustomer.jsp, how many instances of actionForm, action, actionmappings will be created ?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A servlet only has one instances in the server, but it will create a new thread to handle every new request.
 
lalit upadheyay
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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) ?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
lalit upadheyay
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David.

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 ?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, they won't be the same form--how could they be? One is created per-request, one is per-session.

Like I said-I'd just check. I honestly don't remember if it's an action for every specific mapping--I suspect it's per-mapping, but that's a guess.
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(That seems to be correct; I just looked at the RequestProcessor.processActionCreate, and it looks up only by class name.)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic