Skip to content

Instantly share code, notes, and snippets.

@chathurangat
Created November 26, 2017 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chathurangat/665e0e44b2f7b5fa16c883f9bf5e63f3 to your computer and use it in GitHub Desktop.
Save chathurangat/665e0e44b2f7b5fa16c883f9bf5e63f3 to your computer and use it in GitHub Desktop.
public void runAsyncWorkersWithFutureReturnType() throws Exception
{
LOGGER.info(" start of returning async worker");
Future<String> future = asyncWorkerReturn.execute();
String result = (String) this.getResultOfFuture(future);
LOGGER.info(" returned result is [" + result + "] ");
}
private Object getResultOfFuture(Future future) throws Exception
{
if (future.isDone()) {
return future.get();
}
LOGGER.info(" waiting for result ");
Thread.sleep(1000);
return getResultOfFuture(future);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment