Follow these steps to implement the example:
- Create a class named ExecutableTask and specify that it implements the Callable interface parameterized by the String class:
public class ExecutableTask implements Callable<String> {
- Declare a private String attribute called name. It will store the name of the task. Implement the getName() method to return the value of this attribute:
private final String name; public String getName(){ return name; }
- Implement the constructor of the class to initialize the name of the task:
public ExecutableTask(String name){ this.name=name; }
- Implement the call() method. Put the task to sleep for a random period of time and return a message with the name of the task:
@Override ...