@@ -0,0 +1,1511 @@
+package com.njust.test.learn;%0A%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.Executors;%0Aimport java.util.concurrent.Semaphore;%0A%0Apublic class SemaphoreDemo%0A%7B%0A    public static void main(String%5B%5D args)%0A    %7B%0A        ExecutorService executorService = Executors.newCachedThreadPool();%0A        %0A        Semaphore semaphore = new Semaphore(5);%0A        %0A        for (int i = 0; i %3C 10; i++)%0A        %7B%0A            executorService.execute(() -%3E %7B%0A                %0A                //%E8%8E%B7%E5%8F%96%E9%94%81%0A                try%0A                %7B%0A                    semaphore.acquire();%0A                %7D%0A                catch (InterruptedException e)%0A                %7B%0A                    e.printStackTrace();%0A                %7D%0A                System.out.println(Thread.currentThread().getName() + %22 %E5%B7%B2%E8%BF%9B%E5%85%A5: %3C---%22);%0A                %0A                try%0A                %7B%0A                    Thread.sleep((long)(Math.random() * 1000));%0A                %7D%0A                catch (InterruptedException e)%0A                %7B%0A                    e.printStackTrace();%0A                %7D%0A                %0A                //%E9%87%8A%E6%94%BE%E9%94%81%0A                semaphore.release();%0A                System.out.println(%0A                    Thread.currentThread().getName() + %22 %E5%B7%B2%E9%80%80%E5%87%BA: ---%3E %22);%0A                //%E5%9B%A0%E4%B8%BA%E4%B8%8D%E5%9C%A8semaphore%E7%9A%84acquire%E5%92%8Crelease%E5%BD%A2%E6%88%90%E7%9A%84%E9%94%81%E8%8C%83%E5%9B%B4%E5%86%85%EF%BC%8CavailablePermits%E7%9A%84%E5%80%BC%E5%8F%AF%E8%83%BD%E4%B8%8D%E5%AF%B9%0A                System.out.println(%22%E5%BD%93%E5%89%8D%E5%8F%AF%E7%94%A8%E4%B8%AA%E6%95%B0(%E6%8E%A5%E8%BF%91%E7%9A%84):%22 + semaphore.availablePermits());%0A                %0A            %7D);%0A        %7D%0A        %0A        executorService.shutdown();%0A    %7D%0A%7D%0A

Create SemaphoreDemo.java