Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Action Singleton query

 
Graham VMead
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks for your reply/time Marc.
 
Graham VMead
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic