import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class Main {
private static volatile int sCnt = 0;
private static class TestRun implements Runnable {
@Override
public void
run() {
int num = sCnt++;
System.out.println("Run(" + num + ") - Start");
try {
Thread.sleep(2000);
} catch (InterruptedException ignored) { }
System.out.println("Run(" + num + ") - End");
}
};
public static void
main(String[] args) {
ThreadPoolExecutor tpe = new ThreadPoolExecutor
(2,
2,
Long.MAX_VALUE,
TimeUnit.MILLISECONDS,
new LinkedBlockingQueue());
int num = 10;
while (0 < num--)
tpe.execute(new TestRun());
}
}