File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Action Singleton query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Action Singleton query" Watch "Action Singleton query" New topic
Author

Action Singleton query

Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
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

Joined: Sep 22, 2003
Posts: 154
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

Joined: Feb 05, 2003
Posts: 4727

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.


A good workman is known by his tools.
Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
Thanks for your reply/time Marc.
Graham VMead
Ranch Hand

Joined: Sep 22, 2003
Posts: 154
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Action Singleton query