import java.util.concurrent.*;
import java.util.*;
class MyRunnable implements Runnable {
protected int id;
MyRunnable(int id) {
this.id = id;
}
public void run() {
try {
String name = Thread.currentThread().getName();
System.out.println(id + " -- " + name);
Thread.sleep(10);
} catch (InterruptedException e) {
System.out.println("interrupted!");
}
}
}
class Main {
public static void main(String[] args) {
ExecutorService es = Executors.newFixedThreadPool(4);
for (int i = 0; i < 10; i++) {
es.execute(new Thread(new MyRunnable(i)));
}
es.shutdown();
System.out.println("done!");
}
}
To embed this program on your website, copy the following code and paste it into your website's HTML: