craigmcc 02/03/15 18:17:35
Modified: src/share/org/apache/struts/action Tag: STRUTS_1_0_BRANCH
ActionServlet.java
Log:
Port fix for 7060 (double checked locking allocating Action instances)
to the 1.0 branch.
PR: Bugzilla #7060
Submitted by: Michael Rimov <rimovm at centercomp.com>
Revision Changes Path
No revision
No revision
1.68.2.5 +34 -33
jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
Index: ActionServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
retrieving revision 1.68.2.4
retrieving revision 1.68.2.5
diff -u -r1.68.2.4 -r1.68.2.5
--- ActionServlet.java 7 Oct 2001 04:49:15 -0000 1.68.2.4
+++ ActionServlet.java 16 Mar 2002 02:17:34 -0000 1.68.2.5
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
1.68.2.4 2001/10/07 04:49:15 martinc Exp $
- * $Revision: 1.68.2.4 $
- * $Date: 2001/10/07 04:49:15 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
1.68.2.5 2002/03/16 02:17:34 craigmcc Exp $
+ * $Revision: 1.68.2.5 $
+ * $Date: 2002/03/16 02:17:34 $
*
* ====================================================================
*
@@ -231,7 +231,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.68.2.4 $ $Date: 2001/10/07 04:49:15 $
+ * @version $Revision: 1.68.2.5 $ $Date: 2002/03/16 02:17:34 $
*/
public class ActionServlet
@@ -245,7 +245,7 @@
* The set of Action instances that have been created and initialized,
* keyed by the fully qualified Java class name.
*/
- protected FastHashMap actions = new FastHashMap();
+ protected HashMap actions = new HashMap();
/**
@@ -999,9 +999,7 @@
protected void initActions() {
synchronized (actions) {
- actions.setFast(false);
actions.clear();
- actions.setFast(true);
}
}
@@ -1609,37 +1607,40 @@
protected Action processActionCreate(ActionMapping mapping,
HttpServletRequest request) {
- // Acquire the Action instance we will be using
+ // Acquire the Action instance we will be using (if there is one)
String actionClass = mapping.getType();
- if (debug >= 1)
+ if (debug >= 1) {
log(" Looking for Action instance for class " + actionClass);
- Action actionInstance = (Action) actions.get(actionClass);
- if (actionInstance == null) {
- synchronized (actions) {
- if (debug >= 1)
- log(" Double checking for Action instance already there");
- // Double check to avoid a race condition
- actionInstance = (Action) actions.get(actionClass);
- if (actionInstance != null)
- return (actionInstance);
- // Go ahead and create the new Action instance
- // ASSERT: This will never ever happen more than once
- // for a particular action class name
- try {
- if (debug >= 1)
- log(" Creating new Action instance");
- Class clazz = Class.forName(actionClass);
- actionInstance = (Action) clazz.newInstance();
- actionInstance.setServlet(this);
- actions.put(actionClass, actionInstance);
- } catch (Throwable t) {
- log("Error creating Action instance for path '" +
- mapping.getPath() + "', class name '" +
- actionClass + "'", t);
- return (null);
+ }
+ Action actionInstance = null;
+ synchronized (actions) {
+
+ // Return any existing Action instance of this class
+ actionInstance = (Action) actions.get(actionClass);
+ if (actionInstance != null) {
+ if (debug >= 2) {
+ log(" Returning existing Action instance");
}
+ return (actionInstance);
+ }
+
+ // Create and return a new Action instance
+ if (debug >= 2) {
+ log(" Creating new Action instance");
+ }
+ try {
+ Class clazz = Class.forName(actionClass);
+ actionInstance = (Action) clazz.newInstance();
+ actionInstance.setServlet(this);
+ actions.put(actionClass, actionInstance);
+ } catch (Throwable t) {
+ log("Error creating Action instance for path '" +
+ mapping.getPath() + "', class name '" +
+ actionClass + "'", t);
+ return (null);
}
}
+
return (actionInstance);
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>