The reader-writer problem with java threading and semaphore