Search code examples
javasocketstimeouthttpurlconnection

Issues using multiple HttpURLConnection sends in parallel?


Currently, I am designing a module in Java that collects data and sends them in parallel different API endpoints on the same destination address. They are being sent in parallel using threads.

Because they are being sent to the same destination IP address, are there issues that will occur when sending the information using HttpURLConnection? I am thinking that they may use the same base port/socket, even though each transmission uses a new HttpURLConnection object.

Will they end up being sent one by one? And if there are issues with the connection (such as timeouts), will the timeouts add up for each connection if they are sent one-by-one?


Solution

  • As stated in the docs:

    Each HttpURLConnection instance is used to make a single request but the
    underlying network connection to the HTTP server may be transparently
    shared by other instances.
    

    Which mean that it may depend on JVM that you are using. It seems as they may end up being sent one by one.