public class SemApp { public static void main(String[] args) { Runnable limitedCall = new Runnable() { final Random rand = new Random(); final Semaphore available = new Semaphore(3); int count = 0; public void run() { int time = rand.nextInt(15); int num = count++;
try { available.acquire();
System.out.println("Executing " + "long-running action for " + time + " seconds... #" + num);