Follow these steps to implement the example:
- Create a class named Task and specify that it implements the Callable interface parameterized by the String class. Implement the call() method. Write a message to the console and put it to sleep for 100 milliseconds inside an infinite loop:
public class Task implements Callable<String> { @Override public String call() throws Exception { while (true){ System.out.printf("Task: Test\n"); Thread.sleep(100); } }
- Implement the main class of the example by creating a class named Main and adding the main() method to it:
public class Main { public static void main(String[] args) {
- Create a ThreadPoolExecutor object using the newCachedThreadPool() method of the Executors ...