|
From: Tom C. <cT...@wo...> - 2004-04-07 22:40:22
|
> > SpringAction's looking up of the corresponding Spring bean and setting the > > ActionServlet can be significantly optimized. Actually, I consider the > > current implementation unsafe: It first sets the ActionServlet on the located > > Action (a shared instance) and then resets it to null again (on each > > execution!). This is not at all thread-safe. Juergen is right when he questions the thread-safety of resetting the ActionServlet back to null. We've been doing some performance testing on a project build using Hibernate, Spring and Struts, and have found a neat little race condition with the SpringAction. Symptom: During high load we saw NPE's in the system log coming from actions invoked by the SpringAction. After a code review, we found that these were due to a null ActionServlet being present in the action. This was rather funny since the SpringAction provides the ActionServlet instance to each action it invokes. BUT it also clears the action in a finally block --> that's the problem. The solutions we have considered: 1. Don't configure actions as singletons in Spring. This is the obvious solution, but not really a nice one, seeing as Actions are (sort of) singletons in Struts, so why should it be any different in Spring. 2. Stop clearing the ActionServlet in the finally block of SpringAction. This is preferred, but since clearing the action is actually s Struts lifecycle event (i.e. it tells the action to cleanup its resources), it may still be required. This is where we put a little Spring-specific code into each action that needs resource cleanup --> each such action should implement org.springframework.beans.factory.DisposableBean so that it can cleanup when Spring tells it, rather than when Struts (or the SpringAction) does. Its actually appropriate for this, since we are using Spring-configured Struts actions, so why not have Spring control their destruction as well. Just my opinion, mind you. Tom. |