Processing results for Runnable objects in the Executor framework
The Executor framework allows the execution of concurrent tasks that returns a result using the Callable and Future interfaces. The traditional concurrent programming in Java is based on Runnable objects, but this kind of object doesn't return a result.
In this recipe, you will learn how to adapt a Runnable object to simulate a Callable one, allowing a concurrent task to return a result.
Getting ready
The example of this recipe has been implemented using the Eclipse IDE. If you use Eclipse, or another IDE such as NetBeans, open it and create a new Java project.
How to do it...
Perform the following steps to implement the example:
- Create a class named
FileSearchand specify that it implements theRunnableinterface. This class implements the file search operation:
public class FileSearch implements Runnable { - Declare two private
Stringattributes: one namedinitPath, which will store the initial folder for the search operation...