FileLocker.locksMap.get(file).wait();
should be
FileLocker.locksMap.get(file).acquire();
wait
in this case is waiting on the Object monitor. Since you are not synchronized on the semaphore ie:
Semaphore s = FileLocker.locksMap.get(file);
synchronized(s){
s.wait();
}
you get your exception. The acquire
is offered by Semaphore and handles that synchronization for you.
Note You'll also run into the same situation with notify()
instead of release()