You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Eric Johnson <er...@tibco.com> on 2004/08/07 02:43:07 UTC
Re: DO NOT REPLY [Bug 30514] New: - HttpClient deadlocks under
multithreaded access
bugzilla@apache.org wrote:
[snip]
> /**
> * Keep hitting a URL, with no sleep time.
> */
> class ClientThread implements Runnable
> {
> protected Thread m_thread;
> protected boolean m_running = true;
>
> public ClientThread( )
> {
> }
>
> public void run( )
> {
> m_thread = Thread.currentThread( );
> try
> {
> while ( m_running )
> {
> PostMethod httppost = new PostMethod( m_serverURL.getPath( ) );
> httppost.setRequestBody( "some random stuff that doesn't
>matter" );
>
> try
> {
> // print out something so we know when there are active
> // threads
> System.out.print( "." );
> m_client.executeMethod( httppost );
> }
> catch ( Throwable t )
> {
>
// here you should add:
httppost.releaseConnection()
>}
> }
> }
> catch ( Throwable t )
> {
> t.printStackTrace( System.out );
> m_running = false;
> }
> }
> }
>}
>
>
If you don't call releaseConnection(), HttpClient doesn't know whether
you're done reading the response to the request, so it doesn't free up
the connection for re-use, and the MultiThreadedConnectionManager
eventually appears to deadlock, while it is really waiting for you to
call releaseConnection().
-Eric.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org