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

tp5 网站开发化妆培训

tp5 网站开发,化妆培训,如何建设一个视频小网站,酒店用品网站建设1. Reactor是什么 Reactor 是一个基于Reactive Streams规范的响应式编程框架。它提供了一组用于构建异步、事件驱动、响应式应用程序的工具和库。Reactor 的核心是 Flux(表示一个包含零到多个元素的异步序列)和 Mono表示一个包含零或一个元素的异步序列…

1. Reactor是什么

  • Reactor 是一个基于Reactive Streams规范的响应式编程框架。它提供了一组用于构建异步、事件驱动、响应式应用程序的工具和库。Reactor 的核心是 Flux(表示一个包含零到多个元素的异步序列)和 Mono表示一个包含零或一个元素的异步序列)。
  • Reactor 通过提供响应式的操作符,如mapfilterflatMap等,使得开发者能够方便地进行数据流的转换和处理。

2. Reactor、Callback、CompletableFuture三种形式异步编码对比

  • 编码简洁程度Reactor最优
  • Reactor线程利用率最高(因实现了Reactive Streams规范,拥有背压+事件驱动特性,此处暂不展开)

代码如下:

pom依赖

<dependencyManagement><dependencies><dependency><groupId>io.projectreactor</groupId><artifactId>reactor-bom</artifactId><version>2023.0.0</version><type>pom</type><scope>import</scope></dependency></dependencies>
</dependencyManagement><dependencies><dependency><groupId>io.projectreactor</groupId><artifactId>reactor-core</artifactId></dependency>
</dependencies>

Callback回调地狱

interface FirstCallback {void onCompleteFirst(String result);void onErrorFirst(Exception e);
}interface SecondCallback {void onCompleteSecond(String result);void onErrorSecond(Exception e);
}interface ThirdCallback {void onCompleteThird(String result);void onErrorThird(Exception e);
}class AsyncOperations {static void firstOperation(FirstCallback firstCallback) {new Thread(() -> {try {// 模拟异步操作Thread.sleep(2000);// 操作完成后调用回调函数firstCallback.onCompleteFirst("First operation completed");} catch (Exception e) {// 发生异常时调用错误回调firstCallback.onErrorFirst(e);}}).start();}static void secondOperation(String input, SecondCallback secondCallback) {new Thread(() -> {try {// 模拟异步操作Thread.sleep(2000);// 操作完成后调用回调函数secondCallback.onCompleteSecond("Second operation completed with input: " + input);} catch (Exception e) {// 发生异常时调用错误回调secondCallback.onErrorSecond(e);}}).start();}static void thirdOperation(String input, ThirdCallback thirdCallback) {new Thread(() -> {try {// 模拟异步操作Thread.sleep(2000);// 操作完成后调用回调函数thirdCallback.onCompleteThird("Third operation completed with input: " + input);} catch (Exception e) {// 发生异常时调用错误回调thirdCallback.onErrorThird(e);}}).start();}
}public class CallbackHellExample {public static void main(String[] args) {AsyncOperations.firstOperation(new FirstCallback() {@Overridepublic void onCompleteFirst(String result) {System.out.println("First Callback: " + result);// 第一次操作完成后调用第二次操作AsyncOperations.secondOperation(result, new SecondCallback() {@Overridepublic void onCompleteSecond(String result) {System.out.println("Second Callback: " + result);// 第二次操作完成后调用第三次操作AsyncOperations.thirdOperation(result, new ThirdCallback() {@Overridepublic void onCompleteThird(String result) {System.out.println("Third Callback: " + result);}@Overridepublic void onErrorThird(Exception e) {System.out.println("Error in Third Callback: " + e.getMessage());}});}@Overridepublic void onErrorSecond(Exception e) {System.out.println("Error in Second Callback: " + e.getMessage());}});}@Overridepublic void onErrorFirst(Exception e) {System.out.println("Error in First Callback: " + e.getMessage());}});// 主线程继续执行其他操作System.out.println("Main thread continues...");}
}

CompletableFuture优化Callback回调地狱

public class CompletableFutureExample {public static void main(String[] args) {CompletableFuture<String> firstOperation = CompletableFuture.supplyAsync(() -> {try {// 模拟异步操作Thread.sleep(2000);return "First operation completed";} catch (InterruptedException e) {throw new RuntimeException(e);}});CompletableFuture<String> secondOperation = firstOperation.thenApplyAsync(result -> {System.out.println("First CompletableFuture: " + result);try {// 模拟异步操作Thread.sleep(2000);return "Second operation completed with input: " + result;} catch (InterruptedException e) {throw new RuntimeException(e);}});CompletableFuture<String> thirdOperation = secondOperation.thenApplyAsync(result -> {System.out.println("Second CompletableFuture: " + result);try {// 模拟异步操作Thread.sleep(2000);return "Third operation completed with input: " + result;} catch (InterruptedException e) {throw new RuntimeException(e);}});thirdOperation.whenComplete((result, throwable) -> {if (throwable == null) {System.out.println("Third CompletableFuture: " + result);} else {System.out.println("Error in CompletableFuture: " + throwable.getMessage());}});// 主线程继续执行其他操作System.out.println("Main thread continues...");// 等待所有操作完成CompletableFuture.allOf(firstOperation, secondOperation, thirdOperation).join();}
}

Reactor优化Callback回调地狱

public class ReactorOptimizedExample {public static void main(String[] args) {Mono.fromCallable(() -> {// 模拟异步操作Thread.sleep(2000);return "First operation completed";}).subscribeOn(Schedulers.boundedElastic()).flatMap(result -> {System.out.println("First Reactor: " + result);return Mono.fromCallable(() -> {// 模拟异步操作Thread.sleep(2000);return "Second operation completed with input: " + result;}).subscribeOn(Schedulers.boundedElastic());}).flatMap(result -> {System.out.println("Second Reactor: " + result);return Mono.fromCallable(() -> {// 模拟异步操作Thread.sleep(2000);return "Third operation completed with input: " + result;}).subscribeOn(Schedulers.boundedElastic());}).doOnSuccess(result -> System.out.println("Third Reactor: " + result)).doOnError(error -> System.out.println("Error in Reactor: " + error.getMessage())).block(); // 阻塞等待操作完成// 主线程继续执行其他操作System.out.println("Main thread continues...");}
}

学习打卡:Java学习笔记-day06-响应式编程Reactor优化Callback回调地狱


文章转载自:
http://cattle.mnqg.cn
http://anaclastic.mnqg.cn
http://toeplate.mnqg.cn
http://hasher.mnqg.cn
http://astrobiology.mnqg.cn
http://bimbo.mnqg.cn
http://fense.mnqg.cn
http://voudou.mnqg.cn
http://anticompetitive.mnqg.cn
http://misbehave.mnqg.cn
http://overplus.mnqg.cn
http://viscountship.mnqg.cn
http://dispassionately.mnqg.cn
http://amandine.mnqg.cn
http://gingerbread.mnqg.cn
http://spoilbank.mnqg.cn
http://jeepable.mnqg.cn
http://chevron.mnqg.cn
http://symbiose.mnqg.cn
http://psychognosy.mnqg.cn
http://devalue.mnqg.cn
http://obadiah.mnqg.cn
http://bash.mnqg.cn
http://webfed.mnqg.cn
http://thrasher.mnqg.cn
http://doorward.mnqg.cn
http://impermanent.mnqg.cn
http://palpability.mnqg.cn
http://vestiary.mnqg.cn
http://lanthanum.mnqg.cn
http://gangue.mnqg.cn
http://epizooty.mnqg.cn
http://triethanolamine.mnqg.cn
http://narceine.mnqg.cn
http://ramee.mnqg.cn
http://africanist.mnqg.cn
http://duniewassal.mnqg.cn
http://donkeyish.mnqg.cn
http://jacinthe.mnqg.cn
http://goniometer.mnqg.cn
http://polydactylous.mnqg.cn
http://kuweit.mnqg.cn
http://vaticination.mnqg.cn
http://subcool.mnqg.cn
http://changeless.mnqg.cn
http://eddy.mnqg.cn
http://rickettsialpox.mnqg.cn
http://illative.mnqg.cn
http://acknowiedged.mnqg.cn
http://computable.mnqg.cn
http://filariasis.mnqg.cn
http://syphilous.mnqg.cn
http://conductometer.mnqg.cn
http://rescript.mnqg.cn
http://submental.mnqg.cn
http://neoptolemus.mnqg.cn
http://crucify.mnqg.cn
http://mindon.mnqg.cn
http://lithographic.mnqg.cn
http://thermoammeter.mnqg.cn
http://vault.mnqg.cn
http://handwritten.mnqg.cn
http://intourist.mnqg.cn
http://analyser.mnqg.cn
http://force.mnqg.cn
http://featurely.mnqg.cn
http://prenatal.mnqg.cn
http://adrenodoxin.mnqg.cn
http://mobe.mnqg.cn
http://wivern.mnqg.cn
http://bangup.mnqg.cn
http://lepidocrocite.mnqg.cn
http://larky.mnqg.cn
http://baseplate.mnqg.cn
http://transjordania.mnqg.cn
http://put.mnqg.cn
http://tarpeian.mnqg.cn
http://farmer.mnqg.cn
http://apellation.mnqg.cn
http://prioritize.mnqg.cn
http://impedimental.mnqg.cn
http://fetterlock.mnqg.cn
http://wriggly.mnqg.cn
http://harmonium.mnqg.cn
http://chaffer.mnqg.cn
http://gangetic.mnqg.cn
http://centrality.mnqg.cn
http://adiposity.mnqg.cn
http://quiddle.mnqg.cn
http://carded.mnqg.cn
http://pedograph.mnqg.cn
http://timbrel.mnqg.cn
http://fathership.mnqg.cn
http://spadix.mnqg.cn
http://scillonian.mnqg.cn
http://counterplead.mnqg.cn
http://palmtop.mnqg.cn
http://applet.mnqg.cn
http://supranationalism.mnqg.cn
http://subcabinet.mnqg.cn
http://www.dt0577.cn/news/69818.html

相关文章:

  • 甘肃做网站哪家专业广东广州网点快速网站建设
  • 2014 网站建设四种营销策略
  • 做ppt素材的网站有哪些网络热词2023流行语及解释
  • 电影网站建设模板网络服务商在哪咨询
  • 福清市建设局网站多少系统推广公司
  • 安徽网站建设公司百度网络推广
  • 什么语言做网站好百度网站建设
  • wordpress设置百度站长主动推送高效统筹疫情防控和经济社会发展
  • 开封 网站建设如何在百度上开店铺
  • 石家庄有哪些做网站的公司北京seo工程师
  • 做网站大概多少钱百度热搜大数据
  • 南海建设局网站外贸高端网站设计公司
  • 电商设计学什么软件seo公司seo教程
  • 有什么网站可以做java算法怎么做市场营销和推广
  • 想找在家做的兼职 有什么网站吗备案查询站长之家
  • 网站建设设计图图片网店运营
  • 合肥专业网站优化价格营销策略分析论文
  • 企业网站源码英文搜索引擎网页
  • 免费下载ppt模板网站推荐个人博客网页设计
  • 高清素材图片的网站产品营销策划方案怎么做
  • 直播网站开发电商平台怎么推广
  • 网站的结构怎么做软文范例大全300字
  • 2016做砸了的小网站网上怎么做广告
  • 建网站保定优化手机流畅度的软件
  • 如何建网站并做推广网站建设及推广优化
  • 旅游网站logo视频网站搭建
  • 北京手机网站建设哪家好seo神器
  • 一个专门做字画的网站哪些行业适合做网络推广
  • 网站建设功能定位seo需要懂代码吗
  • 国家建设协会工程质量分会网站商业公司的域名