Use Runnable interface to create a thread pool

step:

Create a thread pool object
is created Runnable interface subclass object
submitted Runnable interface subclass object
close the thread pool
instance:

class TaskRunnable implements Runnable{

@Override
public void RUN () {
for (int I = 0; I <10; I ++) {
System.out.println ( "Custom task execution thread" + I);
}
}
}
public class {the ThreadPool

static void main public (String [] args) {
// create a thread pool object parameters 5, representing 5 thread pool threads
ExecutorService = newFixedThreadPool-Service (5);
// Create a thread Runnable task object
TaskRunnable task = new TaskRunnable () ;
// get the thread pool thread object
service.submit (Task);
System.out.println ( "----------------------");
/ / reacquisition a thread object
service.submit (Task);
// Close thread pool
service.shutdown (http://www.amjmh.com);
}

}

---------------------

Guess you like

Origin www.cnblogs.com/liyanyan665/p/11359759.html