Package us.google.www;
Import Java.util.concurrent.ExecutorService;
Import java.util.concurrent.Executors;
/**
* Thread pool
* @author chongrubujing
*
*/
public class ThreadPoolDemo {
public static void Main (string[] args) {
//create a single thread pool
executorservice es = Executors.newsinglethreadexecutor ();
Create a fixed size thread pool
executorservice es1 = Executors.newfixedthreadpool (2);
Create a cacheable thread pool
executorservice es2 = Executors.newcachedthreadpool ();
Create a wireless size thread pool
executorservice es3 = Executors.newscheduledthreadpool (2);
Mythread my = new Mythread ();
Mythread my1 = new Mythread ();
Execute thread
es3.execute (my);
Es3.execute (MY1);
}
}
Class Mythread implements Runnable
{
@Override public
Void Run () {for
(int i = 0; I <10; i++) {
try {
thread.sleep (1000);
} catch (inte Rruptedexception e) {
e.printstacktrace ();
}
System.out.println ("mythread-" +i);
}
}