zoukankan      html  css  js  c++  java
  • guava LoadingCache 不阻塞

    代码

      LoadingCache<String, String> loadingCache = CacheBuilder.newBuilder()
                    .refreshAfterWrite(2, TimeUnit.SECONDS).maximumSize(5)
                    .build(CacheLoader.asyncReloading(new CacheLoader<String, String>() {
                        @Override
                        public String load(String key) throws Exception {
                            System.out.println(Thread.currentThread().getName() + " 加载数据开始---");
                            Thread.sleep(1000);
                            Random random = new Random();
                            System.out.println(Thread.currentThread().getName() + " 加载数据结束----");
                            return "value:" + random.nextInt(10000);
                        }
                    }, ForkJoinPool.commonPool()));
    
            while (true){
    //            String s = cache.get(1);
                String s = loadingCache.get("1");
                System.out.println(s);
                Thread.sleep(100);
            }
  • 相关阅读:
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    How to build and run ARM Linux on QEMU from scratch
    How to debug Android Native Application with eclipse
  • 原文地址:https://www.cnblogs.com/dongma/p/15598278.html
Copyright © 2011-2022 走看看