Hi,
I have following problem. Recently in code review we found some places,
where one very young and very inexperienced developer was directly
instantiating an action:
in execute of ActionA:
...
ActionB b = new ActionB();
b.callSomeMethod();
...
Unfortunately ActionB was getting some resources in constructor (creating a
JacORB stub) so any call to ActionA resulted in actually creating a
ThreadPool on both client and
server side, as well, as creating a tcp-ip connection between two machines.
Since we were always relying on the existence of exactly one instance of an
Action, creating references to these kind resources from the constructor
seemed to be ok. Now we moved
the new Stub() call from the constructor of the Action in the static{}
block, which solved the problem for this particular action.
The question is now, how can I ensure, that an action is actually created
once, and from proper "caller" without changing 500 existing action classes.
The only thing I could imagine, would be introducing a test mode, and if
running in test mode, throw an exception in the BaseAction (mother of all
actions) constructor, parsing the stackTrace, whether the struts request
processor was the caller of the constructor and deny the creation otherwise.
Not very elegant, isn't it?
Any other (and hopefully better) suggestions?
regards
Leon