!7 p { int poolSize = 4, queueSize = 10; int keepAliveSeconds = 15; // how long idle threads are kept alive NotifyingBlockingThreadPoolExecutor threadPoolExecutor = new(poolSize, queueSize, keepAliveSeconds, TimeUnit.SECONDS); for (int i = 1; i <= 50; i++) { final int _i = i; threadPoolExecutor.execute(r { sleepSeconds(1); print(_i) }); print("Queued " + i); } threadPoolExecutor.shutdown(); threadPoolExecutor.awaitTermination(1, TimeUnit.DAYS); }