Created
September 2, 2015 04:42
-
-
Save gansai/6a3d969ac185b8e788dc to your computer and use it in GitHub Desktop.
Illustration of ListeningExecutorService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListeningExecutorServiceIllus | |
{ | |
//Just for illustration purpose, not a working version. | |
//Creation of ListeningExecutorService | |
class MyCallbackRunnable implements Runnable | |
{ | |
@Override | |
public void run() { | |
System.out.println(" I got called by a listenable future"); | |
} | |
} | |
public void illustrationMethod() | |
{ | |
ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10)); | |
//Creation of ListenableFuture | |
ListenableFuture listeningFuture = service.submit(new Callable() { | |
public ReturnType call() { | |
Thread.sleep(20000); | |
ReturnType returnVariable = new ReturnType(); | |
return returnVariable; | |
} | |
}); | |
//Creation of callback executor | |
Executor mycallbackExecutor = Executors.newFixedThreadPool(10); | |
//Registering callbacks with listenableFuture | |
listeningFuture.addListener(new MyCallbackRunnable(),mycallbackExecutor ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment