I donβt know why the send() call can take so long, but if it is too slow for you, then just upload the send() call to another thread:
public class SendThread extends Thread { private HttpClient client; private HttpExchange exchange; public SendThread(HttpClient client, HttpExchange exchange) { this.client = client; this.exchange = exchange; } @Override public void run() { client.send(exchange); } }
Then you can do:
new SendThread(client, exchange).start();
... instead of:
client.send(httpExchange);
If you want to try to find out why the library takes so long, you can also try reading the source code . In short, I would say that 1) what send() does is not entirely trivial, and 2) the only thing that seems asynchronous is the transfer of the actual data / payload to the server; things like making an initial connection to the server are performed synchronously as part of the send() call.
source share