Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ..

like image 698
pavan Avatar asked Jan 24 '12 06:01

pavan


2 Answers

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.

like image 83
aroth Avatar answered Oct 19 '22 22:10

aroth


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

like image 21
Sandeep Pathak Avatar answered Oct 19 '22 23:10

Sandeep Pathak