Search in sources :

Example 1 with LockException

use of lucee.commons.lock.LockException in project Lucee by lucee.

the class RWWrap method lock.

public Lock lock(K token, long timeout, boolean readOnly) throws LockException, LockInterruptedException {
    if (timeout <= 0)
        throw new LockException("timeout must be a postive number");
    RWWrap<K> wrap;
    // K token=key;
    synchronized (locks) {
        RWLock<K> lock;
        lock = locks.get(token);
        if (lock == null) {
            locks.put(token, lock = new RWLock<K>(token));
        }
        lock.inc();
        wrap = new RWWrap<K>(lock, readOnly);
    }
    try {
        wrap.lock(timeout);
    } catch (LockException e) {
        synchronized (locks) {
            wrap.getLock().dec();
        }
        throw e;
    } catch (LockInterruptedException e) {
        synchronized (locks) {
            wrap.getLock().dec();
        }
        throw e;
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        synchronized (locks) {
            wrap.getLock().dec();
        }
        throw new PageRuntimeException(Caster.toPageException(t));
    }
    return wrap;
}
Also used : LockException(lucee.commons.lock.LockException) LockInterruptedException(lucee.commons.lock.LockInterruptedException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Aggregations

LockException (lucee.commons.lock.LockException)1 LockInterruptedException (lucee.commons.lock.LockInterruptedException)1 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)1