Author: remy.maucherat(a)jboss.com
Date: 2011-04-07 11:55:10 -0400 (Thu, 07 Apr 2011)
New Revision: 1697
Modified:
trunk/java/org/apache/jasper/Constants.java
trunk/java/org/apache/jasper/runtime/PerThreadTagHandlerPool.java
trunk/java/org/apache/jasper/runtime/TagHandlerPool.java
Log:
- I don't understand why reuse calls predestroy (get does not call post construct if
the tag is not instantiated). Drop that.
- Use the thread local pool by default, but lower the size (only nesting will actually
require more than one).
- Use the instance manager by default.
Modified: trunk/java/org/apache/jasper/Constants.java
===================================================================
--- trunk/java/org/apache/jasper/Constants.java 2011-04-06 22:20:35 UTC (rev 1696)
+++ trunk/java/org/apache/jasper/Constants.java 2011-04-07 15:55:10 UTC (rev 1697)
@@ -94,7 +94,7 @@
/**
* Default tag handler pool size.
*/
- public static final int MAX_POOL_SIZE =
Integer.parseInt(System.getProperty("org.apache.jasper.Constants.MAX_POOL_SIZE",
"16"));
+ public static final int MAX_POOL_SIZE =
Integer.parseInt(System.getProperty("org.apache.jasper.Constants.MAX_POOL_SIZE",
"4"));
/**
* The query parameter that causes the JSP engine to just
@@ -143,7 +143,7 @@
(System.getSecurityManager() != null);
public static final boolean USE_INSTANCE_MANAGER_FOR_TAGS =
-
Boolean.valueOf(System.getProperty("org.apache.jasper.Constants.USE_INSTANCE_MANAGER_FOR_TAGS",
"false")).booleanValue();
+
Boolean.valueOf(System.getProperty("org.apache.jasper.Constants.USE_INSTANCE_MANAGER_FOR_TAGS",
"true")).booleanValue();
public static final boolean INJECT_TAGS =
Boolean.valueOf(System.getProperty("org.apache.jasper.Constants.INJECT_TAGS",
"false")).booleanValue();
Modified: trunk/java/org/apache/jasper/runtime/PerThreadTagHandlerPool.java
===================================================================
--- trunk/java/org/apache/jasper/runtime/PerThreadTagHandlerPool.java 2011-04-06 22:20:35
UTC (rev 1696)
+++ trunk/java/org/apache/jasper/runtime/PerThreadTagHandlerPool.java 2011-04-07 15:55:10
UTC (rev 1697)
@@ -37,9 +37,9 @@
private int maxSize;
// For cleanup
- private Vector perThreadDataVector;
+ private Vector<PerThreadData> perThreadDataVector;
- private ThreadLocal perThread;
+ private ThreadLocal<PerThreadData> perThread;
private static class PerThreadData {
Tag handlers[];
@@ -51,7 +51,7 @@
*/
public PerThreadTagHandlerPool() {
super();
- perThreadDataVector = new Vector();
+ perThreadDataVector = new Vector<PerThreadData>();
}
protected void init(ServletConfig config) {
@@ -64,8 +64,8 @@
}
}
- perThread = new ThreadLocal() {
- protected Object initialValue() {
+ perThread = new ThreadLocal<PerThreadData>() {
+ protected PerThreadData initialValue() {
PerThreadData ptd = new PerThreadData();
ptd.handlers = new Tag[maxSize];
ptd.current = -1;
@@ -90,12 +90,20 @@
if(ptd.current >=0 ) {
return ptd.handlers[ptd.current--];
} else {
- try {
- return (Tag) handlerClass.newInstance();
- } catch (Exception e) {
- throw new JspException(e.getMessage(), e);
- }
- }
+ try {
+ if (Constants.USE_INSTANCE_MANAGER_FOR_TAGS) {
+ return (Tag) instanceManager.newInstance(handlerClass);
+ } else {
+ Tag instance = (Tag) handlerClass.newInstance();
+ if (Constants.INJECT_TAGS) {
+ instanceManager.newInstance(instance);
+ }
+ return instance;
+ }
+ } catch (Exception e) {
+ throw new JspException(e.getMessage(), e);
+ }
+ }
}
/**
@@ -107,8 +115,8 @@
*/
public void reuse(Tag handler) {
PerThreadData ptd=(PerThreadData)perThread.get();
- if (ptd.current < (ptd.handlers.length - 1)) {
- ptd.handlers[++ptd.current] = handler;
+ if (ptd.current < (ptd.handlers.length - 1)) {
+ ptd.handlers[++ptd.current] = handler;
} else {
handler.release();
}
@@ -118,14 +126,22 @@
* Calls the release() method of all tag handlers in this tag handler pool.
*/
public void release() {
- Enumeration enumeration = perThreadDataVector.elements();
+ Enumeration<PerThreadData> enumeration = perThreadDataVector.elements();
while (enumeration.hasMoreElements()) {
- PerThreadData ptd = (PerThreadData)enumeration.nextElement();
+ PerThreadData ptd = enumeration.nextElement();
if (ptd.handlers != null) {
for (int i=ptd.current; i>=0; i--) {
if (ptd.handlers[i] != null) {
ptd.handlers[i].release();
- }
+ if (Constants.INJECT_TAGS ||
Constants.USE_INSTANCE_MANAGER_FOR_TAGS) {
+ try {
+ instanceManager.destroyInstance(ptd.handlers[i]);
+ } catch (Exception e) {
+ log.warn("Error processing preDestroy on tag
instance of "
+ + ptd.handlers[i].getClass().getName(), e);
+ }
+ }
+ }
}
}
}
Modified: trunk/java/org/apache/jasper/runtime/TagHandlerPool.java
===================================================================
--- trunk/java/org/apache/jasper/runtime/TagHandlerPool.java 2011-04-06 22:20:35 UTC (rev
1696)
+++ trunk/java/org/apache/jasper/runtime/TagHandlerPool.java 2011-04-07 15:55:10 UTC (rev
1697)
@@ -37,7 +37,7 @@
public static final String OPTION_TAGPOOL="tagpoolClassName";
public static final String OPTION_MAXSIZE="tagpoolMaxSize";
- private Logger log = Logger.getLogger(TagHandlerPool.class);
+ protected Logger log = Logger.getLogger(TagHandlerPool.class);
// index of next available tag handler
private int current;
@@ -52,11 +52,10 @@
Class c=Class.forName( tpClassName );
result=(TagHandlerPool)c.newInstance();
} catch (Exception e) {
- e.printStackTrace();
- result=null;
+ result = null;
}
}
- if( result==null ) result=new TagHandlerPool();
+ if( result==null ) result=new PerThreadTagHandlerPool();
result.init(config);
return result;
@@ -151,14 +150,6 @@
}
// There is no need for other threads to wait for us to release
handler.release();
- if (Constants.INJECT_TAGS || Constants.USE_INSTANCE_MANAGER_FOR_TAGS) {
- try {
- instanceManager.destroyInstance(handler);
- } catch (Exception e) {
- log.warn("Error processing preDestroy on tag instance of "
- + handler.getClass().getName(), e);
- }
- }
}
/**
Show replies by date