Import Java.util.concurrent.ExecutorService;
Import java.util.concurrent.Executors;
Import Java.util.concurrent.TimeUnit;
public class Threadpooltest {
/**
* @param args
*/
public static void Main (string[] args) {
Executorservice ThreadPool = Executors.newfixedthreadpool (3);
Executorservice ThreadPool = Executors.newcachedthreadpool ();
Executorservice ThreadPool = Executors.newsinglethreadexecutor ();
for (int i=1;i<=10;i++) {
Final int task = i;
Threadpool.execute (New Runnable () {
@Override
public void Run () {
for (int j=1;j<=10;j++) {
try {
Thread.Sleep (20);
catch (Interruptedexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
System.out.println (Thread.CurrentThread (). GetName () + ' is looping of ' + j + ' for Task ' + task);
}
}
});
}
System.out.println ("All of the tasks have committed!");
Threadpool.shutdownnow ();
Executors.newscheduledthreadpool (3). Scheduleatfixedrate (
New Runnable () {
@Override
public void Run () {
System.out.println ("bombing!");
}},
6,
2,
Timeunit.seconds);
}
}