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

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

Prepare for your Java exam with our ultimate quiz based on 'Thinking in Java'. Engage with expertly crafted questions that enhance your learning process. Perfect for Java enthusiasts looking to solidify their knowledge!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

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.