Package net.sf.ehcache.concurrent

Examples of net.sf.ehcache.concurrent.Mutex


     *                              acquire a lock in that time
     * @throws RuntimeException     if thrown the lock will not released. Catch and call<code>put(new Element(key, null));</code>
     *                              to release the lock acquired.
     */
    public Element get(final Object key) throws RuntimeException, LockTimeoutException {
        Mutex lock = getLockForKey(key);
        try {
            if (timeoutMillis == 0) {
                lock.acquire();
            } else {
                boolean acquired = lock.attempt(timeoutMillis);
                if (!acquired) {
                    StringBuffer message = new StringBuffer("Lock timeout. Waited more than ")
                            .append(timeoutMillis)
                            .append("ms to acquire lock for key ")
                            .append(key).append(" on blocking cache ").append(cache.getName());
                    throw new LockTimeoutException(message.toString());
                }
            }
            final Element element = cache.get(key);
            if (element != null) {
                //ok let the other threads in
                lock.release();
                return element;
            } else {
                //don't release the read lock until we put
                return null;
            }
View Full Code Here


            return;
        }
        Object key = element.getObjectKey();
        Object value = element.getObjectValue();

        Mutex lock = getLockForKey(key);
        try {
            if (value != null) {
                cache.put(element);
            } else {
                cache.remove(key);
            }
        } finally {
            //Release the readlock here. This will have been acquired in the get, where the element was null
            lock.release();
        }
    }
View Full Code Here

            Element element = backingCache.get(key);

            if (element == null) {
                element = super.get(key);
            } else {
                Mutex lock = stripedMutex.getMutexForKey(key);
                try {
                    lock.acquire();
                    update(key);
                } finally {
                    lock.release();
                }
            }
            return element;
        } catch (final Throwable throwable) {
            // Could not fetch - Ditch the entry from the cache and rethrow
View Full Code Here

TOP

Related Classes of net.sf.ehcache.concurrent.Mutex

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.