jstrachan 2002/08/12 12:11:46
Modified: jelly/src/java/org/apache/commons/jelly/impl TagScript.java
BeanTagScript.java DynaTagScript.java
jelly/src/java/org/apache/commons/jelly JellyContext.java
Log:
Patch to disable Tag caching by default
Revision Changes Path
1.18 +21 -7 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java
Index: TagScript.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/TagScript.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- TagScript.java 1 Aug 2002 09:53:17 -0000 1.17
+++ TagScript.java 12 Aug 2002 19:11:46 -0000 1.18
@@ -105,7 +105,14 @@
/** The Log to which logging calls will be made. */
private static final Log log = LogFactory.getLog(TagScript.class);
- /** thread local storage for the tag used by the current thread */
+ /**
+ * Thread local storage for the tag used by the current thread.
+ * This allows us to pool tag instances, per thread to reduce object construction
+ * over head, if we need it.
+ *
+ * Note that we could use the stack and create a new tag for each invocation
+ * if we made a slight change to the Script API to pass in the parent tag.
+ */
private ThreadLocal tagHolder = new ThreadLocal();
/** The attribute expressions that are created */
@@ -351,7 +358,14 @@
tag.setParent( parentTag );
tag.setBody( tagBody );
}
-
+
+ /**
+ * Flushes the current cached tag so that it will be created, lazily, next invocation
+ */
+ protected void clearTag() {
+ tagHolder.set(null);
+ }
+
/**
* Output the new namespace prefixes used for this element
*/
1.14 +10 -5 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java
Index: BeanTagScript.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/BeanTagScript.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- BeanTagScript.java 1 Aug 2002 09:53:17 -0000 1.13
+++ BeanTagScript.java 12 Aug 2002 19:11:46 -0000 1.14
@@ -182,6 +182,11 @@
catch (Exception e) {
handleException(e);
}
+ finally {
+ if ( ! context.isCacheTags() ) {
+ clearTag();
+ }
+ }
}
1.11 +10 -5 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynaTagScript.java
Index: DynaTagScript.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/impl/DynaTagScript.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DynaTagScript.java 1 Aug 2002 09:53:17 -0000 1.10
+++ DynaTagScript.java 12 Aug 2002 19:11:46 -0000 1.11
@@ -143,5 +143,10 @@
catch (Exception e) {
handleException(e);
}
+ finally {
+ if ( ! context.isCacheTags() ) {
+ clearTag();
+ }
+ }
}
}
1.22 +30 -0 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java
Index: JellyContext.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- JellyContext.java 4 Aug 2002 06:38:45 -0000 1.21
+++ JellyContext.java 12 Aug 2002 19:11:46 -0000 1.22
@@ -104,6 +104,10 @@
/** Do we export our variables to parent context? */
private boolean shouldExport = false;
+ /** Should we cache Tag instances, per thread, to reduce object contruction overhead?
*/
+ private boolean cacheTags = false;
+
+
/**
* The class loader to use for instantiating application objects.
* If not specified, the context class loader, or the class loader
@@ -140,6 +144,7 @@
this.currentURL = parent.currentURL;
this.taglibs = parent.taglibs;
this.variables.put("parentScope", parent.variables);
+ this.cacheTags = cacheTags;
init();
}
@@ -608,8 +613,32 @@
public void setCurrentURL(URL currentURL) {
this.currentURL = currentURL;
}
+
+ /**
+ * Returns whether caching of Tag instances, per thread, is enabled.
+ * Caching Tags can boost performance, on some JVMs, by reducing the cost of
+ * object construction when running Jelly inside a multi-threaded application server
+ * such as a Servlet engine.
+ *
+ * @return whether caching of Tag instances is enabled.
+ */
+ public boolean isCacheTags() {
+ return cacheTags;
+ }
/**
+ * Sets whether caching of Tag instances, per thread, is enabled.
+ * Caching Tags can boost performance, on some JVMs, by reducing the cost of
+ * object construction when running Jelly inside a multi-threaded application server
+ * such as a Servlet engine.
+ *
+ * @param cacheTags Whether caching should be enabled or disabled.
+ */
+ public void setCacheTags(boolean cacheTags) {
+ this.cacheTags = cacheTags;
+ }
+
+ /**
* Return the class loader to be used for instantiating application objects
* when required. This is determined based upon the following rules:
* <ul>
@@ -706,4 +735,5 @@
protected JellyContext createChildContext() {
return new JellyContext(this);
}
+
}
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>
|