Package net.sf.ehcache.concurrent

Examples of net.sf.ehcache.concurrent.Sync


     *                              to release the lock acquired.
     */
    @Override
    public Element get(final Object key) throws RuntimeException, LockTimeoutException {

        Sync lock = getLockForKey(key);
        acquiredLockForKey(key, lock, LockType.READ);
        Element element;
        try {
            element = underlyingCache.get(key);
        } finally {
            lock.unlock(LockType.READ);
        }
        if (element == null) {
            acquiredLockForKey(key, lock, LockType.WRITE);
            element = underlyingCache.getQuiet(key);
            if (element != null) {
                if (underlyingCache.isStatisticsEnabled()) {
                    element = underlyingCache.get(key);
                }
                lock.unlock(LockType.WRITE);
            }
        }
        return element;
    }
View Full Code Here


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

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

TOP

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

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.