What are two differences between Callable and Runnable?
A.
A Callable can be executed by a ExecutorService, but a Runnable cannot.
B.
A Callable can be passed to a Thread, but a Runnable cannot.
C.
A Callable can throw an Exception when executing, but a Runnable cannot.
D.
A Callable can return a value when executing, but a Runnable cannot.
C D
ExecutorService executor = …; // … represents some executor creation
Euture taskFuture = executor.submit(new Callable()
{
@Override
public String[] call()
{
String[] entries = …;
// Access online dictionaries with search word and populate entries with their resulting entries.
//return entries;
throw new ExecutionException(“no way to search the entry”);
}
});
// Do stuff.
String entries;
try{
entries = taskFuture.get();
}
catch(ExecutionException e){
logger.log(e.message);
}