samples/reentrant/src/org/apidesign/reentrant/NonReentrantLock.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 30 Oct 2014 21:30:10 +0100
changeset 409 40cabcdcd2be
permissions -rw-r--r--
Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
jtulach@111
     1
package org.apidesign.reentrant;
jtulach@111
     2
jtulach@111
     3
import java.util.concurrent.locks.ReentrantLock;
jtulach@111
     4
jtulach@111
     5
final class NonReentrantLock extends ReentrantLock {
jtulach@111
     6
    @Override
jtulach@111
     7
    public void lock() {
jtulach@111
     8
        if (isHeldByCurrentThread()) {
jtulach@111
     9
            throw new IllegalStateException("Attempt to reentrant lock");
jtulach@111
    10
        }
jtulach@111
    11
        super.lock();
jtulach@111
    12
    }
jtulach@111
    13
jtulach@111
    14
    @Override
jtulach@111
    15
    public void lockInterruptibly() throws InterruptedException {
jtulach@111
    16
        if (isHeldByCurrentThread()) {
jtulach@111
    17
            throw new IllegalStateException("Attempt to reentrant lock");
jtulach@111
    18
        }
jtulach@111
    19
        super.lockInterruptibly();
jtulach@111
    20
    }
jtulach@111
    21
    
jtulach@111
    22
}