File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Whay action class is not singleton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Whay action class is not singleton" Watch "Whay action class is not singleton" New topic

Whay action class is not singleton

Suvoraj Biswas

Joined: Apr 02, 2008
Posts: 5
Since we've only one instance of Action class instantiated for any requests, so why struts designers have not made it as a singleton class.

Stuck in the middle of Java/PHP/Ajax/Javascript/Linux development?<br />For free help on any topics and free articles in latest technologies visit: <a href="" target="_blank" rel="nofollow"></a>
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Originally posted by Suvoraj Biswas:
Since we've only one instance of Action class instantiated for any requests

I'm not sure how Action is implemented or used, but the above is often said about Servlets, and it's not quite true:
the "one instance per servlet" model is a bit of a gloss-over. The truth is that each registered name for a servlet (but not each alias) is associated with one instance of the servlet. The name used to access the servlet determines which instance handles the request. This makes sense because the impression to the client should be that differently named servlets operate independently. The separate instances are also a requirement for servlets that accept initialization parameters

Java Servlet Programming

The Singleton pattern is considered as a Bad Idea by more than a few people.
In the case of Action, it would place an artificial and unnecessary restriction on the implementation of Struts. It's one thing to say there will "probably" be one instance and enforcing it by making Action a singleton.

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: Whay action class is not singleton
It's not a secret anymore!