Code example for ReentrantLock

Methods: lock, unlock

0
    @Override 
    public E get(int location) {
        if (entities != null) {
            E entity = entities.get(location);
            if (entity == null) {
                lock.lock();
                try { 
                    entity = entities.get(location);
                    if (entity == null) {
                        entity = loadEntity(location);
                        entities.set(location, entity);
                        // Ignore FindBugs: increment of volatile is fine here because we use a lock 
                        loadedCount++;
                        if (loadedCount == size) {
                            cursor.close();
                        } 
                    } 
                } finally { 
                    lock.unlock();
                } 
            } 
            return entity;
        } else { 
            return loadEntity(location);