Code example for Semaphore

Methods: acquireUninterruptiblyrelease

0
 
    // One permit per core on the server 
    final Semaphore semaphore = new Semaphore(2);
 
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        semaphore.acquireUninterruptibly();
        try { 
            // do CPU intensive job 
        } finally { 
            semaphore.release();
        } 
    } 
}