Hi I am new to java so not sure if i am going the right way about this. I am using the executor services and my threads are implementing runnable.
What i want to be able to do is return results or any exceptions back to the calling class. I cant do this with runnable, so have been reading up on Runnable with a Future. ot sure how this would be implemented. In my caling class I can make checks to see if the thread is complete (isdone() ?) and get any exceptions with get(), but in the class which implements the runnable not sure how I would set any exceptions that can be picked up by the calling class? Also would the calling class have to sit in a continuous while loop waiting for the isdone() to complete?
posted 2 years ago
The javadocs of the Future class have an example of how to return a String object from thread, but you use any other class instead of String.
As for handling exceptions, you should catch ExecutionException - that's what the JVM will throw if the Future class threw an exception.