classLoadTime=(int) (System.currentTimeMillis() -t1);
- initServlet(servlet);
-
- // Register our newly initialized instance
singleThreadModel = servlet instanceof SingleThreadModel;
if (singleThreadModel) {
if (instancePool == null)
instancePool = new Stack<Servlet>();
}
+
+ initServlet(servlet);
+
fireContainerEvent("load", this);
loadTime=System.currentTimeMillis() -t1;
private synchronized void initServlet(Servlet servlet)
throws ServletException {
- if (instanceInitialized) return;
+ if (instanceInitialized && !singleThreadModel) return;
// Call the initialization method of this servlet
try {
public static final int BUG51445_THREAD_COUNT = 5;
- public void testBug51445() throws Exception {
+ public void testBug51445AddServlet() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Must have a real docBase - just use temp
}
+ public void testBug51445AddChild() throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ // Must have a real docBase - just use temp
+ StandardContext ctx = (StandardContext)
+ tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+
+ StandardWrapper wrapper = new StandardWrapper();
+ wrapper.setServletName("Bug51445");
+ wrapper.setServletClass(Bug51445Servlet.class.getName());
+ ctx.addChild(wrapper);
+ ctx.addServletMapping("/", "Bug51445");
+
+ tomcat.start();
+
+ // Start the threads
+ Bug51445Thread[] threads = new Bug51445Thread[5];
+ for (int i = 0; i < BUG51445_THREAD_COUNT; i ++) {
+ threads[i] = new Bug51445Thread(getPort());
+ threads[i].start();
+ }
+
+ // Wait for threads to finish
+ for (int i = 0; i < BUG51445_THREAD_COUNT; i ++) {
+ threads[i].join();
+ }
+
+ Set<String> servlets = new HashSet<String>();
+ // Check the result
+ for (int i = 0; i < BUG51445_THREAD_COUNT; i ++) {
+ String[] results = threads[i].getResult().split(",");
+ assertEquals(2, results.length);
+ assertEquals("10", results[0]);
+ System.out.println(results[1]);
+ assertFalse(servlets.contains(results[1]));
+ servlets.add(results[1]);
+ }
+
+ }
+
private static class Bug51445Thread extends Thread {
private int port;
Improve the handling for Servlets that implement the deprecated
SingleThreadModel when embedding Tomcat. (markt)
</fix>
+ <fix>
+ <bug>51445</bug>: Correctly initialise all instances of Servlets that
+ implement SingleThreadModel. Based on a patch by Felix Schumacher.
+ (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">