cglib/src/main/java/net/sf/cglib/core/internal/LoadingCache.java
protected V createEntry(final K key, KK cacheKey, Object v) {
        FutureTask<V> task;
        boolean creator = false;
        if (v != null) {
            // Another thread is already loading an instance
            task = (FutureTask<V>) v;
        } else {
            task = new FutureTask<V>(new Callable<V>() {
                public V call() throws Exception {
                    return loader.apply(key);
                }
            });
            Object prevTask = map.putIfAbsent(cacheKey, task);
            if (prevTask == null) {
                // creator does the load
                creator = true;
                task.run();
            } else if (prevTask instanceof FutureTask) {
                task = (FutureTask<V>) prevTask;
            } else {
                return (V) prevTask;
            }
        }

        V result;
        try {
            result = task.get();
        } catch (InterruptedException e) {
            throw new IllegalStateException("Interrupted while loading cache item", e);
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw ((RuntimeException) cause);
            }
            throw new IllegalStateException("Unable to load cache item", cause);
        }
        if (creator) {
            map.put(cacheKey, result);
        }
        return result;
    }
protected V createEntry(final K key, KK cacheKey, Object v) {
        FutureTask<V> task;
        boolean creator = false;
        if (v != null) {
            // Another thread is already loading an instance
            task = (FutureTask<V>) v;
        } else {
            task = new FutureTask<V>(new Callable<V>() {
                public V call() throws Exception {
                    return loader.apply(key);
                }
            });
            Object prevTask = map.putIfAbsent(cacheKey, task);
            if (prevTask == null) {
                // creator does the load
                creator = true;
                task.run();
            } else if (prevTask instanceof FutureTask) {
                task = (FutureTask<V>) prevTask;
            } else {
                return (V) prevTask;
            }
        }

        V result;
        try {
            result = task.get();
        } catch (InterruptedException e) {
            throw new IllegalStateException("Interrupted while loading cache item", e);
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof RuntimeException) {
                throw ((RuntimeException) cause);
            }
            throw new IllegalStateException("Unable to load cache item", cause);
        }
        if (creator) {
            map.put(cacheKey, result);
        }
        return result;
    }
protected V createEntry ( final K key , KK cacheKey , Object v ) { FutureTask < V > task ; boolean creator = false ; if ( v != null ) { // Another thread is already loading an instance task = ( FutureTask < V > ) v ; } else { task = new FutureTask < V > ( new Callable < V > ( ) { public V call ( ) throws Exception { return loader . apply ( key ) ; } } ) ; Object prevTask = map . putIfAbsent ( cacheKey , task ) ; if ( prevTask == null ) { // creator does the load creator = true ; task . run ( ) ; } else if ( prevTask instanceof FutureTask ) { task = ( FutureTask < V > ) prevTask ; } else { return ( V ) prevTask ; } } V result ; try { result = task . get ( ) ; } catch ( InterruptedException e ) { throw new IllegalStateException ( "Interrupted while loading cache item" , e ) ; } catch ( ExecutionException e ) { Throwable cause = e . getCause ( ) ; if ( cause instanceof RuntimeException ) { throw ( ( RuntimeException ) cause ) ; } throw new IllegalStateException ( "Unable to load cache item" , cause ) ; } if ( creator ) { map . put ( cacheKey , result ) ; } return result ; }
Loads entry to the cache.
If entry is missing, put {@link FutureTask} first so other competing thread might wait for the result.
@param key original key that would be used to load the instance
@param cacheKey key that would be used to store the entry in internal map
@param v null or {@link FutureTask<V>}
@return newly created instance
Loads entry to the cache . If entry is missing put {