Pavan
Pavan

Reputation: 3425

asynchronous HTTP request in java

How to send asynchronous HTTP GET/POST request in java without waiting/reading response ?I don't want to use any third party libraries ..

Upvotes: 11

Views: 14581

Answers (3)

Jove Kuang
Jove Kuang

Reputation: 322

I would suggest using something like the Jetty HttpClient if you don't mind adding the Jetty libraries to your app. Here's a good example from Jetty's wiki page http://wiki.eclipse.org/Jetty/Tutorial/HttpClient.

Upvotes: 0

aroth
aroth

Reputation: 54796

If you're not interested in reading the response at all you can just use URL.openStream() to create a connection and then immediately close the socket (or ignore it and let it time out, if you feel like being mean to the server). This isn't strictly asynchronous, but it will be quite a bit faster than any approach that relies upon fetching and parsing the server's response.

This can of course be made asynchronous by offloading the openStream() calls to another thread, either manually or by using the utilities available in java.util.concurrent.

Upvotes: 5

Sandeep Pathak
Sandeep Pathak

Reputation: 10747

java.util.concurrent can be used .

If you interested is using third party libraries then you might want to take a look at

Async Http Client

Upvotes: 1

Related Questions