Why didn't the ReentrantLock method throw an exception?

package com.example.demo;

import java.util.concurrent.locks.ReentrantLock;

public class Task implements Runnable {
    ReentrantLock lock;
    int i = 0;

    public Task(ReentrantLock lock) {
        this.lock = lock;
    }


    @Override
    public void run() {
        for (int j = 0; j < 10000; jPP) {
            lock.lock();
            iPP;
             lock.unlock();
            System.out.println(Thread.currentThread() + " : " + i);

        }
    }

    public static void main(String[] args) {
        ReentrantLock lock = new ReentrantLock();
        Task task = new Task(lock);
        for (int i = 0; i < 100; iPP) {
            Thread thread = new Thread(task);
            thread.start();

        }


    }
}
In the

book, lock () unlock () says that throwing an exception should be caught, but mine can run

.
Mar.20,2021

Please refer to the jdk documentation:

clipboard.png

clipboard.png

lock does not throw an exception, unlock does throw, but it is checked exception, so there is no need for catch. However, for code between lock and unlock, it is recommended to add try..catch, because this is the only way to ensure that unlock, will not be left out, so the following writing is recommended:

lock.lock();
try {
    xxx;
} finally {
    lock.unlock();
}


The

lock and unlock methods do not have checked exception.

public void unlock() {
        sync.release(1);
    }
     public void lock() {
        sync.lock();
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b31e07-2bdc1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b31e07-2bdc1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?