January 2014
Intermediate to advanced
736 pages
70h 43m
English
Figure J.13 uses an ExecutorService object to manage threads that execute PrintTasks (as defined in Fig. J.12). Lines 11–13 create and name three PrintTasks to execute. Line 18 uses Executors method newCachedThreadPool to obtain an ExecutorService that’s capable of creating new threads as they’re needed by the application. These threads are used by ExecutorService (threadExecutor) to execute the Runnables.
1 // Fig. J.13: TaskExecutor.java 2 // Using an ExecutorService to execute Runnables. 3 import java.util.concurrent.Executors; 4 import java.util.concurrent.ExecutorService; 5 6 public class TaskExecutor 7 { 8 public static ...
Read now
Unlock full access