DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4816>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4816 Container fails to prevent concurrent access to servlet implementing SingleThreadModel Summary: Container fails to prevent concurrent access to servlet implementing SingleThreadModel Product: Tomcat 4 Version: 4.0.1 Final Platform: All OS/Version: All Status: NEW Severity: Normal Priority: Other Component: Catalina AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] If using a multi-threaded client, where each thread issues multiple requests, the servlet below, which implements the SingleThreadedModel interface, will fail to prevent multiple threads running the service() method. I can reproduce easily using 5 threads with 3 requests per thread. Using the same servlet and client code against the resin container, I can easily increase to 100 client threads without failure. ******************************************************************************* package single; import javax.servlet.*; import java.io.IOException; import java.io.PrintWriter; public class SingleModelTestServlet extends GenericServlet implements SingleThreadModel { private int threadCount = 0; private StringBuffer sb = null; public void service ( ServletRequest request, ServletResponse response ) throws ServletException, IOException { /* * The threadCount variable should be at 0 each time service() is invoked * by the container. If a request enters, and it's not zero, fail * the test by throwing a ServletException */ try { assertThreadCount( 0 ); threadCount++; } catch ( MultipleThreadException mte ) { sb = new StringBuffer( 100 ); sb.append( "Thread counter was not 0 upon entering the service() method\n" ); sb.append( "The value found was: " ); sb.append( threadCount ); throw new ServletException( sb.toString() ); } finally { sb = null; } /* * threadCount has now been incremented, loop * for a period of time and assert that threadCount * never changes. After the loop completes, decrement * threadCount and return. */ try { for ( int i = 0; i < 200000; i++ ) { assertThreadCount( 1 ); } } catch ( MultipleThreadException mte ) { sb = new StringBuffer( 75 ); sb.append( "Thread count changed during processing!\n" ); sb.append( "Expected a value of 1, but found: " ); sb.append( threadCount ); throw new ServletException( sb.toString() ); } finally { sb = null; threadCount--; } } private void assertThreadCount( int val ) throws MultipleThreadException { if ( threadCount != val ) { throw new MultipleThreadException(); } } private class MultipleThreadException extends java.lang.Exception { /* * Creates a new <code>MultipleThreadException</code> instance. * */ public MultipleThreadException() { super(); } } } ****************************************************************************** -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>