Reputation: 195
Is it possible to restrict the instantiation of a Struts2 action class to only one instance. Basically enforce the Singleton pattern on the action. I am extending the ActionSupport class.
Upvotes: 0
Views: 793
Reputation: 160251
Technically, sure, I suppose--but the entire framework assumes an instance-per-request, is tested only as such, and I would predict only Very Bad Things if you did so.
Extending ActionSupport
makes that situation even more dire, as everything it adds also assumes a single-instance-per-request. Things like error and info messages, for example, which obviously per-request, are instance properties--so you'd need to re-implement a fair chunk of ActionSupport
to make it thread-safe.
Why would you want to do this, anyway?
Upvotes: 3