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

[EMAIL PROTECTED] changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
           Priority|Other                       |Medium
         Resolution|WORKSFORME                  |



------- Additional Comments From [EMAIL PROTECTED]  2001-11-29 10:19 -------
Guess I requested this to be closed too soon.
I'm able to get the failure to appear with TC 4.01 with 20 client threads.

I'm adding the client code to make this issue easily reproduced.

To run the client issue:  java Client <hostname> <port> <number_of_threads>
<request path>

When a failure occurs, the client will report an Exception that the server
returned a 500.

Check the TC log and the following message, or one similar depending on where
the failure occurred in the Servlet:
javax.servlet.ServletException: Thread counter was not 0 upon entering the
service() method
The value found was: 1


*******************************************************************************
import java.net.HttpURLConnection;
import java.net.URL;

public class Client {

    private static final int SLEEPTIME      = 5000;
    private static final int NUM_REQUESTS   = 3;

    // For Thread Synchronization
    private static int threadCount          = 0;
    private static int threadsDone          = 0;
    private static int errors               = 0;
    private static int port                 = 0;
    private static Object lock              = new Object();
    private static Object startLock         = new Object();
    private static Object workLock          = new Object();
    private static String hostname          = null;
    private static String requestPath       = null;

    public Client( String hostname, int port, int threadCount, String
requestPath ) {
        this.hostname    = hostname;
        this.port        = port;
        this.threadCount = threadCount;
        this.requestPath  = requestPath;
    }

    public void runTest() {

        try {
            Thread[] testThread = new Thread[ threadCount ];

            for ( int i = 0; i < threadCount; i++ ) {
                testThread[ i ] = new Thread( new TestThread( i ), "TestThread-"
+ i );
                testThread[ i ].setPriority( Thread.MAX_PRIORITY );
                testThread[ i ].start();
            }

            synchronized( lock ) {
                while ( threadsDone < testThread.length ) {
                    lock.wait();
                }

                try {
                    Thread.sleep( SLEEPTIME );
                } catch ( Exception e ) {
                    ;
                }
            }

            //notify all to start
            synchronized( startLock ) {
                threadsDone = 0;
                startLock.notifyAll();
            }
            //wait for completion
            synchronized( lock ) {
                while ( threadsDone < testThread.length ) {
                    lock.wait();
                }
            }

            if ( errors > 0 ) {
                System.err.println( "Number of Errors: " + errors );
                System.err.println( "Test FAILED" );
            } else {
                System.out.println( "No Errors.  Test PASSED" );
            }
        } catch ( Exception e ) {
            System.err.println( "Unexpected Exception in runTest()!" );
            System.err.println( "Exception: " + e.toString() );
            System.err.println( "Message: " + e.getMessage() );
            e.printStackTrace();
            System.exit( 1 );
        }
    }

    public static void main( String[] args ) {
        Client client = new Client( args[ 0 ], new Integer( args[ 1 ] ).intValue(),
                        new Integer( args[ 2 ] ).intValue(), args[ 3 ] );
        client.runTest();
        System.exit( 0 );
    }

    class TestThread implements Runnable {

        // Instance variables
        private int threadNum       = 0;
        private boolean synchronize = true;

        public TestThread( int threadNum ) {
            this.threadNum = threadNum;
        }

        public void run() {

            synchronized( lock ) {
                ++threadsDone;
                lock.notifyAll();
            }

            synchronized( startLock ) {
                try {
                    startLock.wait();
                } catch ( InterruptedException ie ) {
                    ;
                }
            }
            this.runSingleThreadModelTest();

            synchronized( lock ) {
                ++threadsDone;
                lock.notifyAll();
            }
        }

        public void runSingleThreadModelTest() {

            for ( int i = 0; i < 3; i++ ) {
                try {
                    URL url = new URL( "http://"; + hostname + ":" + port +
requestPath );
                    HttpURLConnection conn = (HttpURLConnection)
url.openConnection();
                    conn.setRequestMethod( "GET" );
                    conn.connect();
                    int code = conn.getResponseCode();
                    if ( code != HttpURLConnection.HTTP_OK ) {
                        synchronized( lock ) {
                            ++errors;
                        }
                    }
                } catch ( Exception e ) {
                    System.err.println( "Unexpected Exception in
runSingleThreadModelTest()!" );
                    System.err.println( "Exception: " + e.toString() );
                    System.err.println( "Message: " + e.getMessage() );
                    e.printStackTrace();
                    System.exit( 1 );
               }
           }

        }

    }
}

************************************************

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to