Reputation: 400
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?
Upvotes: 4
Views: 1196
Reputation: 9492
The question if the connection should be reused or not is a question of connection pooling and the implementation of the HttpURLConnection class itself. It has nothing to do with the JVM.
If we keep the things agnostic from the HttpURLConnection.At the end of the day everything translates into sockets(endpoints) and the connection targeting the socket. You can have multiple connections per endpoint. The answer to your question is that they will not be sent one by one as long as the connection is not pooled.
This topic is explaining the concept of socket and connection in great details. I would suggest reading it.
What is the difference between a port and a socket?
Connection pooling with respect of HttpURLConnection is possible though and explained in details here: Java HttpURLConnection and pooling
Upvotes: 0
Reputation: 820
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.
Upvotes: 1