@@ -0,0 +1,2247 @@
+package reentrantlock;%0A%0Aimport java.util.concurrent.locks.ReentrantLock;%0A%0Apublic class InterruptLock implements Runnable %7B%0A    private static ReentrantLock lock1 = new ReentrantLock();%0A    private static ReentrantLock lock2 = new ReentrantLock();%0A%0A    private static int i = 0;%0A%0A    public InterruptLock(int i) %7B%0A        i = i;%0A    %7D%0A%0A    @Override%0A    public void run() %7B%0A        if (i == 1) %7B%0A            try %7B%0A                System.out.println(Thread.currentThread() + %22ready to get lock1%22);%0A                lock1.lockInterruptibly();%0A                System.out.println(Thread.currentThread() + %22get lock1%22);%0A                Thread.sleep(5000);%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A%0A            try %7B%0A                System.out.println(Thread.currentThread() + %22ready to get lock2%22);%0A                lock2.lockInterruptibly();%0A                System.out.println(Thread.currentThread() + %22get lock2%22);%0A                Thread.sleep(5000);%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A        %7D else %7B%0A%0A            try %7B%0A                System.out.println(Thread.currentThread() + %22ready to get lock2%22);%0A                lock2.lockInterruptibly();%0A                System.out.println(Thread.currentThread() + %22get lock2%22);%0A                Thread.sleep(5000);%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A%0A            try %7B%0A                System.out.println(Thread.currentThread() + %22ready to get lock1%22);%0A                lock1.lockInterruptibly();%0A                System.out.println(Thread.currentThread() + %22get lock1%22);%0A                Thread.sleep(5000);%0A            %7D catch (InterruptedException e) %7B%0A                e.printStackTrace();%0A            %7D%0A%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws InterruptedException %7B%0A        InterruptLock interruptLock = new InterruptLock(1);%0A        Thread thread1 = new Thread(interruptLock);%0A        InterruptLock interruptLock2 = new InterruptLock(2);%0A        Thread thread2 = new Thread(interruptLock2);%0A        thread1.start();%0A        thread2.start();%0A%0A        thread1.join();%0A        thread2.join();%0A    %7D%0A%7D%0A

add reentrantLock 重入锁 中断