Created
July 30, 2020 17:55
-
-
Save AnjaliManhas/ff5acf59e193084ea13646852088b7cb to your computer and use it in GitHub Desktop.
invokeAny() implementation
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
package com.wordpress.compilationerrors; | |
import java.lang.Runnable; | |
import java.lang.*; | |
import java.util.HashSet; | |
import java.util.Set; | |
import java.util.concurrent.*; | |
public class ExecutorServiceExample { | |
public static void main(String[] args) throws InterruptedException, ExecutionException { | |
ExecutorService executorService = Executors.newSingleThreadExecutor(); | |
Set<Callable<String>> callables = new HashSet<Callable<String>>(); | |
callables.add(new Callable<String>() { | |
public String call() throws Exception { | |
return "Task 1"; | |
} | |
}); | |
callables.add(new Callable<String>() { | |
public String call() throws Exception { | |
return "Task 2"; | |
} | |
}); | |
callables.add(new Callable<String>() { | |
public String call() throws Exception { | |
return "Task 3"; | |
} | |
}); | |
String result = executorService.invokeAny(callables); | |
System.out.println("result = " + result); | |
executorService.shutdown(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment