java - HttpURLConnection, skip a file download -
i writing java performance test program fires httpurlconnection.openconnection method within each thread , downloads file web server, not save locally. here code:
httpurlconnection conn = null; inputstream = null; try { url prs = new url(url); conn = (httpurlconnection)prs.openconnection(); if (conn.getresponsecode() == httpstatus.sc_ok && conn.getcontentlength() > 0 ) { = conn.getinputstream(); while (is.read() != -1) { } } else { system.err.println(url+" returned response code : "+conn.getresponsecode()+" , content lengh = "+conn.getcontentlength()); } } catch (exception e) { e.printstacktrace(); } { try { is.close(); } catch (ioexception e) { e.printstacktrace(); } conn.disconnect(); }
the purpose of test see how long take download file (without saving disk) increasing number of threads , measure time takes process each thread on server , client side. not want save file on client side, , read input stream.
the problem each run of program client side performance starts decreasing. not sure, if input stream not getting closed or what.
the idea discard input stream of connection memory each thread.
thanks
Comments
Post a Comment