• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Whay action class is not singleton

 
Suvoraj Biswas
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joe Ess
Bartender
Posts: 9320
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic