Lines 17-22
Link Here
|
17 |
|
17 |
|
18 |
package org.apache.jasper.runtime; |
18 |
package org.apache.jasper.runtime; |
19 |
|
19 |
|
|
|
20 |
import java.util.Iterator; |
21 |
import java.util.Queue; |
22 |
import java.util.concurrent.LinkedBlockingQueue; |
23 |
|
20 |
import javax.servlet.ServletConfig; |
24 |
import javax.servlet.ServletConfig; |
21 |
import javax.servlet.jsp.JspException; |
25 |
import javax.servlet.jsp.JspException; |
22 |
import javax.servlet.jsp.tagext.Tag; |
26 |
import javax.servlet.jsp.tagext.Tag; |
Lines 33-47
Link Here
|
33 |
*/ |
37 |
*/ |
34 |
public class TagHandlerPool { |
38 |
public class TagHandlerPool { |
35 |
|
39 |
|
36 |
private Tag[] handlers; |
|
|
37 |
|
38 |
public static final String OPTION_TAGPOOL = "tagpoolClassName"; |
40 |
public static final String OPTION_TAGPOOL = "tagpoolClassName"; |
39 |
public static final String OPTION_MAXSIZE = "tagpoolMaxSize"; |
41 |
public static final String OPTION_MAXSIZE = "tagpoolMaxSize"; |
40 |
|
42 |
|
41 |
private final Log log = LogFactory.getLog(TagHandlerPool.class); |
43 |
private final Log log = LogFactory.getLog(TagHandlerPool.class); |
42 |
|
44 |
|
43 |
// index of next available tag handler |
45 |
private Queue<Tag> handlers; |
44 |
private int current; |
46 |
|
45 |
protected InstanceManager instanceManager = null; |
47 |
protected InstanceManager instanceManager = null; |
46 |
|
48 |
|
47 |
public static TagHandlerPool getTagHandlerPool(ServletConfig config) { |
49 |
public static TagHandlerPool getTagHandlerPool(ServletConfig config) { |
Lines 77-84
Link Here
|
77 |
if (maxSize < 0) { |
79 |
if (maxSize < 0) { |
78 |
maxSize = Constants.MAX_POOL_SIZE; |
80 |
maxSize = Constants.MAX_POOL_SIZE; |
79 |
} |
81 |
} |
80 |
this.handlers = new Tag[maxSize]; |
82 |
this.handlers = new LinkedBlockingQueue<Tag>(maxSize); |
81 |
this.current = -1; |
|
|
82 |
instanceManager = InstanceManagerFactory.getInstanceManager(config); |
83 |
instanceManager = InstanceManagerFactory.getInstanceManager(config); |
83 |
} |
84 |
} |
84 |
|
85 |
|
Lines 101-112
Link Here
|
101 |
* if a tag handler cannot be instantiated |
102 |
* if a tag handler cannot be instantiated |
102 |
*/ |
103 |
*/ |
103 |
public Tag get(Class<? extends Tag> handlerClass) throws JspException { |
104 |
public Tag get(Class<? extends Tag> handlerClass) throws JspException { |
104 |
Tag handler; |
105 |
Tag handler = handlers.poll(); |
105 |
synchronized (this) { |
106 |
if (handler != null) { |
106 |
if (current >= 0) { |
107 |
return handler; |
107 |
handler = handlers[current--]; |
|
|
108 |
return handler; |
109 |
} |
110 |
} |
108 |
} |
111 |
|
109 |
|
112 |
// Out of sync block - there is no need for other threads to |
110 |
// Out of sync block - there is no need for other threads to |
Lines 134-153
Link Here
|
134 |
* Tag handler to add to this tag handler pool |
132 |
* Tag handler to add to this tag handler pool |
135 |
*/ |
133 |
*/ |
136 |
public void reuse(Tag handler) { |
134 |
public void reuse(Tag handler) { |
137 |
synchronized (this) { |
135 |
if (!handlers.offer(handler)) { |
138 |
if (current < (handlers.length - 1)) { |
136 |
handler.release(); |
139 |
handlers[++current] = handler; |
137 |
try { |
140 |
return; |
138 |
instanceManager.destroyInstance(handler); |
|
|
139 |
} catch (Exception e) { |
140 |
log.warn("Error processing preDestroy on tag instance of " + |
141 |
handler.getClass().getName(), e); |
141 |
} |
142 |
} |
142 |
} |
143 |
} |
143 |
// There is no need for other threads to wait for us to release |
|
|
144 |
handler.release(); |
145 |
try { |
146 |
instanceManager.destroyInstance(handler); |
147 |
} catch (Exception e) { |
148 |
log.warn("Error processing preDestroy on tag instance of " + |
149 |
handler.getClass().getName(), e); |
150 |
} |
151 |
} |
144 |
} |
152 |
|
145 |
|
153 |
/** |
146 |
/** |
Lines 155-167
Link Here
|
155 |
* handler pool. |
148 |
* handler pool. |
156 |
*/ |
149 |
*/ |
157 |
public synchronized void release() { |
150 |
public synchronized void release() { |
158 |
for (int i = current; i >= 0; i--) { |
151 |
Iterator<Tag> iter = handlers.iterator(); |
159 |
handlers[i].release(); |
152 |
while (iter.hasNext()) { |
|
|
153 |
Tag handler = iter.next(); |
154 |
handler.release(); |
160 |
try { |
155 |
try { |
161 |
instanceManager.destroyInstance(handlers[i]); |
156 |
instanceManager.destroyInstance(handler); |
162 |
} catch (Exception e) { |
157 |
} catch (Exception e) { |
163 |
log.warn("Error processing preDestroy on tag instance of " + |
158 |
log.warn("Error processing preDestroy on tag instance of " + |
164 |
handlers[i].getClass().getName(), e); |
159 |
handler.getClass().getName(), e); |
165 |
} |
160 |
} |
166 |
} |
161 |
} |
167 |
} |
162 |
} |