Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


What method is used for non-blocking file lock acquisition?

  1. lock()

  2. tryLock()

  3. unlock()

  4. release()

The correct answer is: tryLock()

TryLock() is used for non-blocking file lock acquisition. This method tries to acquire a lock on a file and returns a boolean value indicating whether it was successful or not. It does not block the thread and allows it to continue executing if the lock could not be acquired. Lock() is a blocking method and will cause the thread to wait until the lock is acquired. Unlock() and release() are used to release a lock that has already been acquired and do not have anything to do with non-blocking file lock acquisition.