I created an application that sends GET requests to a URL and then downloads the full content of this page.
The client sends a GET, for example, stackoverflow.com, and redirects the response to the parser, which has the ability to find all the sources from the page that need to be downloaded with subsequent GET requests.
The method below is used to send these GET requests. It is called many times in a row, with URLs returned by the parser. Most of these URLs are located on the same host and must be able to use a TCP connection.
public static void sendGetRequestToSubObject(String RecUrl) { URL url = new URL(recUrl.toString()); URLConnection connection = url.openConnection (); InputStreamReader isr = new InputStreamReader(connection.getInputStream()); }
Each time this method is called, a new TCP connection is created (using a three-way TCP connection), and then a GET is sent over that connection. But I want to reuse TCP connections to improve performance.
I assume that since I create a new URL object each time the method is called, that way it will work ...
Can someone help me make this better?
Thanks!
source share