Code example for Semaphore

Methods: acquire, release, sleep

0
			final int NO = index;
			Runnable run = new Runnable() {
				public void run() { 
					try { 
						// 获取许可 
						semp.acquire();
						System.out.println("Accessing: " + NO);
						Thread.sleep((long) (Math.random() * 1000));
						// 访问完后,释放 
						System.out.println("Release: " + NO);
						semp.release();
					} catch (InterruptedException e) {
					} 
				} 
			}; 
			exec.execute(run);
		} 
		// 退出线程池 
		exec.shutdown();
	} 
}