java - How to wait for all async REST calls are finished using Unirest? -



java - How to wait for all async REST calls are finished using Unirest? -

being new async programming wondering how van wait futures complete?

in current utilize case have read file , post content line line using json post rest webservice. when in normal way programme exists before futures finished.

below code program.

while ((line = br.readline()) != null) { future<httpresponse<string>> future = unirest.post("http://www.dummy.net") .fields(map) .asstringasync(new callback<string>() { public void completed(httpresponse<string> response) { int code = response.getstatus(); } public void failed(unirestexception e) { system.out.println("the request has failed"); } public void cancelled() { system.out.println("the request has been cancelled"); } } ); }

this code runs , exists before futures have been completed. hint on how can wait futures complete?

put these futures collection, e.g. arraylist. , them all.

list<future> futures = ... // while loop foreach(future f : futures) f.get();

java rest asynchronous unirest

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -