Adapted to java semaphore