I use HttpComponents 4.0.1 and i have an application that has to do about 20 
millions of requests, normal get and post request.
I suddenly engaged a memory leak problem... i found several post where many 
users has the same problem, and they solve it in several ways... but no one 
seem to be the right one.
For testing memory leak i used for retrive pages google.it, as you can
see...

*****************
//test class

public void test_HttpRequest(){

                MyUtil.MyApp.AppHandler app_handler = new 
MyUtil.MyApp.AppHandler();

                for(int i=0; i<10000; i++){

                        HttpGet httpget = new HttpGet("http://www.google.it/";);
                        httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows; 
U; Windows NT 5.1;
en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0 (.NET CLR 3.5.30729)");
                        
                        System.out.println("processing request num: "+(i+1));
                        
                        new C_HttpRequestManager("google.it",
                                        80,//server port
                                        httpget,//method
                                        true,//keep try
                                        5000,//wait time in ms
                                        false,//no proxy
                                        null,//proxy host name
                                        0,//proxy host port
                                        app_handler).getResponse();
                        
                        try {
                                System.out.println("waiting 2 s...");
                                Thread.sleep(2000);
                        } catch (InterruptedException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                }

                System.out.println("requests completed, insert value...");
                MyUtil.MyIO.Util.getLineFromStdInput();
                
        }

 *****************
 now i show you the code about the http class request...
 *****************

...

public void getResponse() {

                final String function_name = "getResponse";

                final String function_name_formatted =
this.class_name+"."+function_name+": ";

                C_HttpResponseStatusEntity response = null;

                do{

                        ccm = new SingleClientConnManager(params, 
supportedSchemes);

                        httpclient = new DefaultHttpClient(ccm, params);

                        try {

                                h_response = httpclient.execute(target_host, 
request);


                        } catch (ClientProtocolException e) {

                                try {
                                        if(this.app_handler.hasLog())
                                                
this.app_handler.log.writeErr(e.toString());
                                } catch (BaseExcp e1) {
                                        // TODO Auto-generated catch block
                                        e1.printStackTrace();
                                }

                                this.h_status = e.toString();
                                this.h_entity = e.toString();

                        } catch (IOException e) {

                                response = this.pharse_IOException(e);

                                
if(response.getStatus().equals(this.SocketTimeoutException)){
                                        if(this.app_handler.hasLog()){
                                                try {
                                                
this.app_handler.log.writeInfo(function_name_formatted+SocketTimeoutException);
                                                } catch (BaseExcp e1) {
                                                        // TODO Auto-generated 
catch block
                                                        e1.printStackTrace();
                                                        
this.app_handler.exitAppCarefully();
                                                }
                                        }
                                        continue;
                                }else{

                                        return response;
                                }


                        }
// Get hold of the response entity
                        HttpEntity entity = this.h_response.getEntity();

                        File f = new File(".\\entity_tmp");
                        
                        java.io.FileOutputStream o = null;
                        try {
                                o = new FileOutputStream(f);
                        } catch (FileNotFoundException e1) {
                                // TODO Auto-generated catch block
                                e1.printStackTrace();
                        }
                        
                        try {
                                entity.writeTo(o);//stram the response to the 
file tmp
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }

        this.request.abort();

                        try {
                                o.close();
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }

        this.keep_try = false;

                }while(this.keep_try);

                this.ccm.shutdown();            

                this.ccm = null;                

        }

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

i hope for some smart suggestion!

Andrea

-- 
View this message in context: 
http://old.nabble.com/Memory-leak---java-heap-space-exception-tp28809331p28809331.html
Sent from the HttpClient-User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to