• Bug
  • Status: Closed
  • Resolution: Fixed
  • drb
  • Reporter: sourceforgetracker
  • September 21, 2009
  • 0
  • Watchers: 0
  • September 22, 2009
  • September 22, 2009

Description

For the method

public Element get(final Object key) throws LockTimeoutException {

This call gets the underlying object, and Blocks if a null element is returned.

        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;
        }

If a RuntimeException is thrown with “cache.get()”, then the BlockingCache will be left in a blocking state.

In my experience, an IOException was thrown in cache.get() and wrapped as a RuntimeException by the SpringJdbcStore.

Perhaps the documentation can be changed to help warn other developers who may run into the same problem.

“Note. If a LockTimeoutException or RuntimeException is thrown while doing a {@link #get} it means the lock was never acquired,”

Sourceforge Ticket ID: 1990091 - Opened By: nobody - 10 Jun 2008 19:16 UTC

Comments

Sourceforge Tracker 2009-09-21

Logged In: YES user_id=693320 Originator: NO

Hi

Sorry you got caught by that. I think it is a documentation issue. I have changed the javadoc as follows:

/** * Looks up an entry. Blocks if the entry is null until a call to {@link #put} is done * to put an Element in. * <p/> * If a put is not done, the lock is never released. * <p/> * If this method throws an exception, it is the responsibility of the caller to catch that exception and call * put(new Element(key, null)); to release the lock acquired. See {@link net.sf.ehcache.constructs.blocking.SelfPopulatingCache} * for an example. * * Note. If a LockTimeoutException is thrown while doing a {@link #get} it means the lock was never acquired, * therefore it is a threading error to call {@link #put} * * @throws LockTimeoutException if timeout millis is non zero and this method has been unable to * acquire a lock in that time * @throws RuntimeException if thrown the lock will not released. Catch and callput(new Element(key, null)); * to release the lock acquired.
*/

That should alert developers accordingly as to the contract.

Thanks for pointing this out.

The fix is in trunk and will be in ehcache-1.5.0 which will be out this weekend.

Greg Comment by: gregluck - 9 Jul 2008 07:29 UTC

Fiona OShea 2009-09-22

Re-opening so that I can properly close out these issues and have correct Resolution status in Jira