<commit_before>package org.banyan.concurrent.base.computetask;

import java.util.concurrent.*;

/**
 * 计算结果缓存包装器
 * User : krisjin
 * Date: 2015/9/15
 */
public class ComputeWrapper<A, V> implements Computable<A, V> {
    //结果缓存
    private final ConcurrentMap<A, Future<V>> cache = new ConcurrentHashMap<A, Future<V>>();
    //计算接口
    private final Computable<A, V> computable;

    //包装器传入计算接口
    public ComputeWrapper(Computable<A, V> computable) {
        this.computable = computable;
    }

    @Override
    public V compute(final A arg) throws InterruptedException, ExecutionException {
        while (true) {
            Future<V> future = cache.get(arg);
            if (future == null) {
                Callable<V> callable = new Callable<V>() {
                    @Override
                    public V call() throws Exception {
                        return computable.compute(arg);
                    }
                };
                FutureTask<V> futureTask = new FutureTask<V>(callable);
                future = cache.putIfAbsent(arg, futureTask);
                if (future == null) {
                    future = futureTask;
                    futureTask.run();
                }
                return future.get();
            } else {
                System.out.println("###################cache hit###################");
                return future.get();
            }

        }
    }

}<commit_msg>update syn test<commit_after>package org.banyan.concurrent.base.computetask;

import java.util.concurrent.*;

/**
 * 计算结果缓存包装器
 * User : krisjin
 * Date: 2015/9/15
 */
public class ComputeWrapper<A, V> implements Computable<A, V> {
    //结果缓存
    private final ConcurrentMap<A, Future<V>> cache = new ConcurrentHashMap<A, Future<V>>();
    //计算接口
    private final Computable<A, V> computable;

    //包装器传入计算接口
    public ComputeWrapper(Computable<A, V> computable) {
        this.computable = computable;
    }

    @Override
    public V compute(final A arg) throws InterruptedException, ExecutionException {
        while (true) {
            Future<V> future = cache.get(arg);
            if (future == null) {
                Callable<V> callable = new Callable<V>() {
                    public V call() throws Exception {
                        return computable.compute(arg);
                    }
                };
                FutureTask<V> futureTask = new FutureTask<V>(callable);
                future = cache.putIfAbsent(arg, futureTask);
                if (future == null) {
                    future = futureTask;
                    futureTask.run();
                }
                return future.get();
            } else {
                System.out.println("###################cache hit###################");
                return future.get();
            }
        }
    }

}
{'fraction_non_alphanumeric': 0.13321616871704745, 'fraction_numerical': 0.00492091388400703, 'mean_word_length': 1.7078972407231208, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '535027', 'n_tokens_mistral': 825, 'n_tokens_neox': 795, 'n_words': 175}