当前位置: 首页 > news >正文

失信人被执行人查询沈阳seo优化排名公司

失信人被执行人查询,沈阳seo优化排名公司,广州网页设计师工资一般多少,查看商标是否被注册官网需求 有一家商店提供的价格是以欧元#xff08;EUR#xff09;计价的#xff0c;但是你希望以美元的方式提供给你的客户。你可以用异步的方式向商店查询指定商品的价格#xff0c;同时从远程的汇率服务那里查到欧元和美元之间的汇率。当二者都结束时#xff0c;再将这两个…需求 有一家商店提供的价格是以欧元EUR计价的但是你希望以美元的方式提供给你的客户。你可以用异步的方式向商店查询指定商品的价格同时从远程的汇率服务那里查到欧元和美元之间的汇率。当二者都结束时再将这两个结果结合起来用返回的商品价格乘以当时的汇率得到以美元计价的商品价格。 实现源码 public class ExchangeService {public enum Money {USD(1.0), EUR(1.35387), GBP(1.69715), CAD(.92106), MXN(.07683);private final double rate;Money(double rate) {this.rate rate;}}public static double getRate(Money source, Money destination) {return getRateWithDelay(source, destination);}private static double getRateWithDelay(Money source, Money destination) {Util.delay();return destination.rate / source.rate;} }public class BestPriceFinder {private final ListShop shops Arrays.asList(new Shop(BestPrice),new Shop(LetsSaveBig),new Shop(MyFavoriteShop),new Shop(BuyItAll) new Shop(ShopEasy));private final Executor executor Executors.newFixedThreadPool(shops.size(), ExecuterThreadFactoryBuilder.build()); }实现方案 你对一个CompletableFuture对象调用了thenCompose方法并向其传递了第二个CompletableFuture而第二个CompletableFuture又需要使用第一个CompletableFuture的执行结果作为输入。但是另一种比较常见的情况是你需要将两个完全不相干的CompletableFuture对象的结果整合起来而且你也不希望等到第一个任务完全结束才开始第二项任务。你应该使用thenCombine方法。thenCombine方法也提供有一个Async的版本。这里如果使用thenCombineAsync会导致BiFunction中定义的合并操作被提交到线程池中由另一个任务以异步的方式执行。 方案1 public ListString findPricesInUSD(String product) {ListCompletableFutureDouble priceFutures new ArrayList();for (Shop shop : shops) {CompletableFutureDouble futurePriceInUSD CompletableFuture.supplyAsync(() - shop.getPrice(product), executor).thenCombine(CompletableFuture.supplyAsync(() - ExchangeService.getRate(Money.EUR, Money.USD), executor), (price, rate) - price * rate);priceFutures.add(futurePriceInUSD);}ListString prices priceFutures.stream().map(CompletableFuture::join).map(price - price is price).collect(Collectors.toList());return prices; }方案2 public ListString findPricesInUSD2(String product) {ListCompletableFutureString priceFutures new ArrayList();for (Shop shop : shops) {CompletableFutureString futurePriceInUSD CompletableFuture.supplyAsync(() - shop.getPrice(product), executor).thenCombine(CompletableFuture.supplyAsync(() - ExchangeService.getRate(Money.EUR, Money.USD), executor), (price, rate) - price * rate).thenApply(price - shop.getName() price is price);priceFutures.add(futurePriceInUSD);}ListString prices priceFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());return prices; }方案3 public ListString findPricesInUSD3(String product) {ListCompletableFutureString priceFutures shops.stream().map(shop - CompletableFuture.supplyAsync(() - shop.getPrice(product)).thenCombine(CompletableFuture.supplyAsync(() - ExchangeService.getRate(Money.EUR, Money.USD)), (price, rate) - price * rate).thenApply(price - shop.getName() price is price)).collect(Collectors.toList());ListString prices priceFutures.stream().map(CompletableFuture::join).collect(Collectors.toList());return prices; }方案4使用Java 7中提供的特性完成上述功能 // 为了更直观地感受一下使用CompletableFuture在代码可读性上带来的巨大提升尝试仅使用Java 7中提供的特性实现以下如上实现 public ListString findPricesInUSDJava7(String product) {ExecutorService executor Executors.newCachedThreadPool();ListFutureDouble priceFutures new ArrayList();for (Shop shop : shops) {final FutureDouble futureRate executor.submit(new CallableDouble() {public Double call() {return ExchangeService.getRate(Money.EUR, Money.USD);}});FutureDouble futurePriceInUSD executor.submit(new CallableDouble() {public Double call() {try {double priceInEUR shop.getPrice(product);return priceInEUR * futureRate.get();} catch (InterruptedException | ExecutionException e) {throw new RuntimeException(e.getMessage(), e);}}});priceFutures.add(futurePriceInUSD);}ListString prices new ArrayList();for (FutureDouble priceFuture : priceFutures) {try {prices.add( price is priceFuture.get());}catch (ExecutionException | InterruptedException e) {e.printStackTrace();}}return prices; }我们能看到创建流水线对同步和异步操作进行混合操作有多么简单随着处理任务和需要合并结果数目的增加这种声明式程序设计的优势也愈发明显。 测试 public static void main(String[] args) {StopWatch stopWatch new StopWatch(性能比较);execute(combined USD findPricesInUSDJava7, () - bestPriceFinder.findPricesInUSDJava7(myPhone27S), stopWatch);execute(combined USD CompletableFuture, () - bestPriceFinder.findPricesInUSD(myPhone27S), stopWatch);execute(combined USD CompletableFuture v2, () - bestPriceFinder.findPricesInUSD2(myPhone27S), stopWatch);execute(combined USD CompletableFuture v3, () - bestPriceFinder.findPricesInUSD3(myPhone27S), stopWatch);StopWatchUtils.logStopWatch(stopWatch); } private static void execute(String msg, SupplierListString s, StopWatch stopWatch) {stopWatch.start(msg);System.out.println(s.get());stopWatch.stop();System.out.println(); }[ price is 91.040141702717, price is 125.1710573102377, price is 158.16078708139523, price is 136.45612204497712, price is 130.0591978746988][ price is 145.62246618545896, price is 123.78887748261509, price is 142.17561724598045, price is 147.48700495707948, price is 148.2901027867818][BestPrice price is 126.3823279607243, LetsSaveBig price is 124.52723804111048, MyFavoriteShop price is 129.1051274535831, BuyItAll price is 114.36072566615553, ShopEasy price is 121.11783256695436][BestPrice price is 168.06251816668828, LetsSaveBig price is 148.38498827435606, MyFavoriteShop price is 119.0272869408407, BuyItAll price is 115.15446874021768, ShopEasy price is 153.35355439427738]性能比较 total cost time 6045 ms combined USD findPricesInUSDJava7 : 1008 ms, 16.67% combined USD CompletableFuture : 2009 ms, 33.23% combined USD CompletableFuture v2 : 2015 ms, 33.33% combined USD CompletableFuture v3 : 1012 ms, 16.74%
http://www.hkea.cn/news/14357903/

相关文章:

  • 苏州吴江建设局招标网站备案不关闭网站怎么样
  • 贵阳网站设计与开发怎么做东莞市网络seo推广企业
  • 网站建设 博采百度广告费一般多少钱
  • 网站建设个人网站推荐好的简历制作网站
  • 哈尔滨网站建设的公司哪家好深圳网站设计南京
  • 怎么建设网站广饶县住房和城乡建设局网站
  • 神州网站制作html怎么写
  • 商业网站是什么青岛网站商城设计
  • 怎么建设自己的论坛网站马鞍山天立建设网站
  • 网站框架地图怎么自己制作图片
  • 17zwd一起做业网站建设部网站首页
  • 大庆城市投资建设网站进广州最新政策
  • 科技企业网站制作最有创意的广告语30条
  • 注册好了域名怎么开始做网站网站改备案
  • 什么网站能免费做推广最大郑州网站建设公司
  • 如何上传到网站根目录闵行网站制作设计公司
  • 做网站技术人员百度关键词价格计算
  • 新办公司网上核名在哪个网站做安平谁做网站好
  • 古装摄影网站建设方案深圳互助资金盘网站开发
  • 网站支付怎么做的昆明做凡科网站
  • 哪个网站有免费的模板什么是主页
  • 合作制作网站避免视觉效果混淆。
  • 移动网站不备案吗html企业网站模板免费下载
  • 学院网站建设 好处网站建设丶金手指下拉12
  • 啤酒网站建设莱芜都市网征婚
  • .net 网站开发工程师网页设计流程要怎么写
  • 绿色食品网站建设论文seo网络推广公司报价
  • 网站点击率代码如何做购物返佣金网站
  • 后台网站模板htmlwordpress不间断音乐
  • 成都科技网站建设咨询注册网站账号审核不通过无法登陆怎么办