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()); } }
'Language > Java' 카테고리의 다른 글
[Java] Java main thread vs. user thread vs. daemon thread. (0) | 2015.10.19 |
---|---|
Compile time에 결정되는 것들 - static final primitives! (0) | 2014.01.15 |
[Java] Visibility에서 추가했으면 하는 것.... (0) | 2011.04.21 |
[Java] Some notable stuffs of VM (0) | 2011.01.06 |
[Java] Simple sample codes to remind... (0) | 2010.12.07 |