• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Action Singleton query

 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I've just been reading Ted Husted et al's Struts in Action book and in here it states that Struts only creates one Action object per Action class and re-uses the instance for subsequent requests that map to this action, i.e a singleton, it then says that this provides for optimum thru put.

I may have got the wrong end of the stick here but I can see how this helps in terms of resource usage but won't this cause a bottleneck where many users are accessing the same action rather than helping throughput and also doesn't it introduce thread safety issues into the design of the action class itself?

TIA Graham
 
Graham VMead
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a few additional thoughts concerning this question is it best to make the action lightweight, request scope and create an instance of a business application handler within the action and delegate to this?
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Graham VMead:

I may have got the wrong end of the stick here but I can see how this helps in terms of resource usage but won't this cause a bottleneck where many users are accessing the same action rather than helping throughput and also doesn't it introduce thread safety issues into the design of the action class itself?

There are only thread safety issues if you try to save state (ie class variables) to your Actions. Keep everything in your methods and you'll be ok.

Just a few additional thoughts concerning this question is it best to make the action lightweight, request scope and create an instance of a business application handler within the action and delegate to this?
You don't make Actions any scope. It's the ActionForms that get placed into scope.
But it IS best to make the Action as lightweight as possible, like a Command Pattern. I wouldn't create an instance of an application handler within the Action... I prefer getting an instance of the handler (or delegate).

These are great questions.

 
Graham VMead
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply/time Marc.
 
Graham VMead
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW You are quite right, by create I meant use a factory to get a new Application handler in the perform/execute method.

Then delegate the business processing to this. The Application handler can then create instance variables to its hearts content because each new thread would get its own instance.

Thanks again
 
Liar, liar, pants on fire! refreshing plug:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic