Java implementation of a priority based semaphore