tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1141502 - in /tomcat/trunk: java/org/apache/catalina/core/StandardWrapper.java test/org/apache/catalina/core/TestStandardWrapper.java webapps/docs/changelog.xml
Date Thu, 30 Jun 2011 12:16:37 GMT
Author: markt
Date: Thu Jun 30 12:16:37 2011
New Revision: 1141502

URL: http://svn.apache.org/viewvc?rev=1141502&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=51445
Correctly initialise all instances of Servlets that implement SingleThreadModel.
Based on a patch by Felix Schumacher.

Modified:
    tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
    tomcat/trunk/test/org/apache/catalina/core/TestStandardWrapper.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java?rev=1141502&r1=1141501&r2=1141502&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java Thu Jun 30 12:16:37 2011
@@ -1115,14 +1115,14 @@ public class StandardWrapper extends Con
 
             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;
@@ -1186,7 +1186,7 @@ public class StandardWrapper extends Con
     private synchronized void initServlet(Servlet servlet)
             throws ServletException {
         
-        if (instanceInitialized) return;
+        if (instanceInitialized && !singleThreadModel) return;
 
         // Call the initialization method of this servlet
         try {

Modified: tomcat/trunk/test/org/apache/catalina/core/TestStandardWrapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestStandardWrapper.java?rev=1141502&r1=1141501&r2=1141502&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestStandardWrapper.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestStandardWrapper.java Thu Jun 30 12:16:37
2011
@@ -333,7 +333,7 @@ public class TestStandardWrapper extends
 
     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
@@ -370,6 +370,46 @@ public class TestStandardWrapper extends
 
     }
 
+    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;

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1141502&r1=1141501&r2=1141502&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Jun 30 12:16:37 2011
@@ -176,6 +176,11 @@
         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">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message