hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Massimo Signori" <sign...@webscience.it>
Subject still got problems with too TCP connections open
Date Mon, 25 Oct 2004 11:49:39 GMT
Hello, i'm still having a lot of problems with my code and with TCP
connections; at this point I just don't know if the problem is HttpClient
but I really don't know how to fix this problem...

here's what my code do: 
Method downloadFileViaHttpClient downloads a ZIP file from a server while
method notifyTimeServer notifies elapsed time to the server every 5 seconds.


Now, here's the code:

HttpClient is instantiated ONE time in both cases.

private void downloadFileViaHttpClient(String remoteFile, String savePath)
throws DownloadException {
        
        
        try {
            logger.debug("DOWNLOADING FILE... " + remoteFile);
            
            method = new GetMethod(remoteFile);
            
            
                
                statusCode=client.executeMethod(method);
                
                FileOutputStream out = new FileOutputStream(savePath);
                
                InputStream in = method.getResponseBodyAsStream();
                
                byte[] buffer = new byte[4096];
                int len = 0;
                while ((len = in.read(buffer)) > 0) {
                    out.write(buffer, 0, len);
                }
                
                in.close();
                out.close();
                
                
        }
        catch	(Exception e) {
             method.releaseConnection();
            throw new
DownloadException(DownloadException.DOWNLOADING_ERROR);
        }
        finally{
            method.releaseConnection();
        }
    }

And the other's method code:

private void notifyTimeServer() {
        
        logger.debug("notifyTimeServer, " + timerURL);
        
        HttpMethod method = new GetMethod(timerURL);
        
                 
            logger.debug("Establishing connection");
            
            try {
                statusCode = client.executeMethod(method);
                
                if (statusCode != -1) {
                 
                    logger.debug("Connection estabilished");
                    byte[] responseBody = method.getResponseBody();
                    
                }
            }
            
            catch (Exception e) {
                logger.error("Error calling jsp "  + e.getMessage());
                                //
            }
            finally{
                method.releaseConnection();
            }
               
    }

NotifyTimeServer is called every 5 seconds... I call releaseConnection...
but... 

Looking with TCPView the number of connections open... about 5000 !!!!

Thanks to all for any help

Best regards, 

Massimo


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


Mime
View raw message