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

邵阳市住房和城乡建设局网站全网vip视频网站怎么做

邵阳市住房和城乡建设局网站,全网vip视频网站怎么做,科技股,wordpress 微博同步背景 CompletableFuture是Java 8中引入的一个类#xff0c;它实现了Future和CompletionStage接口#xff0c;用于表示异步计算的结果。使用CompletableFuture可以方便地编写异步编程的代码#xff0c;并且可以链式地组合多个异步操作。 接口 CompletableFuture实现了Future…背景 CompletableFuture是Java 8中引入的一个类它实现了Future和CompletionStage接口用于表示异步计算的结果。使用CompletableFuture可以方便地编写异步编程的代码并且可以链式地组合多个异步操作。 接口 CompletableFuture实现了Future接口和CompletionStage接口 public class CompletableFutureT implements FutureT, CompletionStageT {//... } 常用API CompletableFuture 提供了很多实用的 API 来处理异步计算的结果。以下是 CompletableFuture 的一些常用 API supplyAsync 含义传入一个Supplier返回一个新的 CompletableFuture public static U CompletableFutureU supplyAsync(SupplierU supplier) {return asyncSupplyStage(ASYNC_POOL, supplier); }public static U CompletableFutureU supplyAsync(SupplierU supplier,Executor executor) {return asyncSupplyStage(screenExecutor(executor), supplier); } runAsync 含义传入一个Runnable返回一个新的CompletableFuture public static CompletableFutureVoid runAsync(Runnable runnable) {return asyncRunStage(ASYNC_POOL, runnable); }public static CompletableFutureVoid runAsync(Runnable runnable,Executor executor) {return asyncRunStage(screenExecutor(executor), runnable); } thenApply 含义对于一个已完成的CompletableFuture的返回值进行同步操作 public U CompletableFutureU thenApply(Function? super T,? extends U fn) {return uniApplyStage(null, fn); } CompletableFutureString future CompletableFuture.supplyAsync(() - result_1); CompletableFutureString future2 future.thenApply(result - result- result); System.out.println(future2.get()); result-result_1 thenApplyAsync 含义对于一个已完成的CompletableFuture的返回值进行异步操作 public U CompletableFutureU thenApplyAsync(Function? super T,? extends U fn) {return uniApplyStage(defaultExecutor(), fn); }public U CompletableFutureU thenApplyAsync(Function? super T,? extends U fn, Executor executor) {return uniApplyStage(screenExecutor(executor), fn); } thenAccept 含义 public CompletableFutureVoid thenAccept(Consumer? super T action) {return uniAcceptStage(null, action); } thenAcceptAsync 含义 public CompletableFutureVoid thenAcceptAsync(Consumer? super T action) {return uniAcceptStage(defaultExecutor(), action); }public CompletableFutureVoid thenAcceptAsync(Consumer? super T action,Executor executor) {return uniAcceptStage(screenExecutor(executor), action); } thenRun 含义 public CompletableFutureVoid thenRun(Runnable action) {return uniRunStage(null, action); } thenRunAsync 含义 public CompletableFutureVoid thenRunAsync(Runnable action) {return uniRunStage(defaultExecutor(), action); }public CompletableFutureVoid thenRunAsync(Runnable action,Executor executor) {return uniRunStage(screenExecutor(executor), action); } thenCombine 含义 public U,V CompletableFutureV thenCombine(CompletionStage? extends U other,BiFunction? super T,? super U,? extends V fn) {return biApplyStage(null, other, fn); } thenCombineAsync 含义 public U,V CompletableFutureV thenCombineAsync(CompletionStage? extends U other,BiFunction? super T,? super U,? extends V fn) {return biApplyStage(defaultExecutor(), other, fn); }public U,V CompletableFutureV thenCombineAsync(CompletionStage? extends U other,BiFunction? super T,? super U,? extends V fn, Executor executor) {return biApplyStage(screenExecutor(executor), other, fn); } 示例 1. 创建CompletableFuture实例可以通过无参数的构造函数来创建一个表示异步计算结果的CompletableFuture实例。 CompletableFutureString future new CompletableFuture(); 2. 提交异步任务可以使用CompletableFuture的静态方法supplyAsync或runAsync来提交异步任务。supplyAsync接受一个Supplier函数式接口表示异步计算的任务runAsync接受一个Runnable接口表示异步执行的任务。这两个方法都可以指定执行异步任务的线程池。 CompletableFutureString future CompletableFuture.supplyAsync(() - {  // 异步计算任务  return Hello;   });  CompletableFutureVoid voidFuture CompletableFuture.runAsync(() - {  // 异步执行任务   }); 完成Future当异步计算任务完成后可以使用CompletableFuture的complete方法来完成Future并设置结果值。如果异步计算任务抛出异常可以使用completeExceptionally方法来完成Future并设置异常信息。 future.complete(Hello);   future.completeExceptionally(new Exception(Error)); 获取结果可以使用CompletableFuture的get方法来获取异步计算的结果。get方法会阻塞当前线程直到异步计算完成并返回结果。如果异步计算抛出异常get方法会抛出ExecutionException异常。如果需要添加超时时间可以使用get方法的重载版本。 String result future.get(); // 阻塞当前线程直到异步计算完成并返回结果 链式组合异步操作可以使用CompletableFuture的thenApply、thenAccept、thenRun等链式方法来组合多个异步操作。这些方法接受一个函数式接口作为参数用于处理前一个CompletableFuture的结果。例如可以使用thenApply方法对前一个CompletableFuture的结果进行转换并返回一个新的CompletableFuture。 CompletableFutureString newFuture future.thenApply(s - s.toUpperCase());
http://www.hkea.cn/news/14422873/

相关文章:

  • linux下用python做网站公司装修图片大全
  • 广州市门户网站建设公司形象墙设计效果图
  • 平台网站开发简报网站建设的行业资讯、
  • 苏州外贸公司网站建设流程好公司网站建设
  • 建设专业网站电话咨询做网站不好做
  • 做商城网站服务器网络营销的六大特征
  • 仿淘宝php c2c电子商务网站模板金属建材企业网站建设方案
  • 如何做个网站教程备案主体负责人 网站负责人
  • 建网站的步骤中国建设银行信用卡
  • html5购物网站图书馆新生专栏网站建设
  • 网站建设工作人员有哪些职责郑州app开发 丁
  • 网站申请qq吕梁市网站建设公司
  • html5网站建设 教程视频电子商务视觉设计
  • 网站建设怎么做呢天元建设集团有限公司宋卫志
  • 网站栏目词行业网站模板
  • 自己怎么开发网站打开百度网页版
  • 百色住房和城乡建设部网站社群运营外包
  • 网页设计作业效果图wordpress用户注册优化
  • 郑州网站改版上海网站制作网
  • 门户网站设计特点高端 网站
  • 可以自己做视频网站吗中国黄金集团j建设公司网站
  • seo站长网周口网站建设哪家好
  • 上海金融网站制作公休闲零食网站建设+中企动力
  • 自己买台服务器做网站网上购物平台口碑排名
  • 现在还有人用asp做网站西安软件开发公司排行
  • 手机网站代码网站和自媒体都可以做
  • 国外扁平化网站设计欣赏企业做网站天津
  • 珠珠宝宝网网站站建建设设电信ip做的网站移动不能访问
  • 网站安装部署网站seo推广平台
  • 如何去做一个网站wordpress jetpack插件