日B视频 亚洲,啪啪啪网站一区二区,91色情精品久久,日日噜狠狠色综合久,超碰人妻少妇97在线,999青青视频,亚洲一区二卡,让本一区二区视频,日韩网站推荐

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

異步神器CompletableFuture萬字詳解!

jf_ro2CN3Fa ? 來源:CSDN ? 作者:CSDN ? 2022-11-15 10:15 ? 次閱讀
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群


CompletableFuture是jdk8的新特性。CompletableFuture實現(xiàn)了CompletionStage接口和Future接口,前者是對后者的一個擴展,增加了異步會點、流式處理、多個Future組合處理的能力,使Java在處理多任務(wù)的協(xié)同工作時更加順暢便利。

一、創(chuàng)建異步任務(wù)

1. supplyAsync

supplyAsync是創(chuàng)建帶有返回值的異步任務(wù)。它有如下兩個方法,一個是使用默認線程池(ForkJoinPool.commonPool())的方法,一個是帶有自定義線程池的重載方法

//帶返回值異步請求,默認線程池
publicstaticCompletableFuturesupplyAsync(Suppliersupplier)

//帶返回值的異步請求,可以自定義線程池
publicstaticCompletableFuturesupplyAsync(Suppliersupplier,Executorexecutor)

測試代碼:

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf=CompletableFuture.supplyAsync(()->{
System.out.println("dosomething....");
return"result";
});

//等待任務(wù)執(zhí)行完成
System.out.println("結(jié)果->"+cf.get());
}


publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
//自定義線程池
ExecutorServiceexecutorService=Executors.newSingleThreadExecutor();
CompletableFuturecf=CompletableFuture.supplyAsync(()->{
System.out.println("dosomething....");
return"result";
},executorService);

//等待子任務(wù)執(zhí)行完成
System.out.println("結(jié)果->"+cf.get());
}

測試結(jié)果:

90bc4a4e-648a-11ed-8abf-dac502259ad0.png

2. runAsync

runAsync是創(chuàng)建沒有返回值的異步任務(wù)。它有如下兩個方法,一個是使用默認線程池(ForkJoinPool.commonPool())的方法,一個是帶有自定義線程池的重載方法

//不帶返回值的異步請求,默認線程池
publicstaticCompletableFuturerunAsync(Runnablerunnable)

//不帶返回值的異步請求,可以自定義線程池
publicstaticCompletableFuturerunAsync(Runnablerunnable,Executorexecutor)

測試代碼:

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf=CompletableFuture.runAsync(()->{
System.out.println("dosomething....");
});

//等待任務(wù)執(zhí)行完成
System.out.println("結(jié)果->"+cf.get());
}


publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
//自定義線程池
ExecutorServiceexecutorService=Executors.newSingleThreadExecutor();
CompletableFuturecf=CompletableFuture.runAsync(()->{
System.out.println("dosomething....");
},executorService);

//等待任務(wù)執(zhí)行完成
System.out.println("結(jié)果->"+cf.get());
}

測試結(jié)果:

90e0da4e-648a-11ed-8abf-dac502259ad0.png

3.獲取任務(wù)結(jié)果的方法

//如果完成則返回結(jié)果,否則就拋出具體的異常
publicTget()throwsInterruptedException,ExecutionException

//最大時間等待返回結(jié)果,否則就拋出具體異常
publicTget(longtimeout,TimeUnitunit)throwsInterruptedException,ExecutionException,TimeoutException

//完成時返回結(jié)果值,否則拋出unchecked異常。為了更好地符合通用函數(shù)形式的使用,如果完成此CompletableFuture所涉及的計算引發(fā)異常,則此方法將引發(fā)unchecked異常并將底層異常作為其原因
publicTjoin()

//如果完成則返回結(jié)果值(或拋出任何遇到的異常),否則返回給定的valueIfAbsent。
publicTgetNow(TvalueIfAbsent)

//如果任務(wù)沒有完成,返回的值設(shè)置為給定值
publicbooleancomplete(Tvalue)

//如果任務(wù)沒有完成,就拋出給定異常
publicbooleancompleteExceptionally(Throwableex)

基于 Spring Boot + MyBatis Plus + Vue & Element 實現(xiàn)的后臺管理系統(tǒng) + 用戶小程序,支持 RBAC 動態(tài)權(quán)限、多租戶、數(shù)據(jù)權(quán)限、工作流、三方登錄、支付、短信、商城等功能

  • 項目地址:https://github.com/YunaiV/ruoyi-vue-pro
  • 視頻教程:https://doc.iocoder.cn/video/

二、異步回調(diào)處理

1. thenApply和thenApplyAsync

thenApply 表示某個任務(wù)執(zhí)行完成后執(zhí)行的動作,即回調(diào)方法,會將該任務(wù)的執(zhí)行結(jié)果即方法返回值作為入?yún)鬟f到回調(diào)方法中,帶有返回值。

測試代碼:

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
return1;
});

CompletableFuturecf2=cf1.thenApplyAsync((result)->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
result+=2;
returnresult;
});
//等待任務(wù)1執(zhí)行完成
System.out.println("cf1結(jié)果->"+cf1.get());
//等待任務(wù)2執(zhí)行完成
System.out.println("cf2結(jié)果->"+cf2.get());
}

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
return1;
});

CompletableFuturecf2=cf1.thenApply((result)->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
result+=2;
returnresult;
});
//等待任務(wù)1執(zhí)行完成
System.out.println("cf1結(jié)果->"+cf1.get());
//等待任務(wù)2執(zhí)行完成
System.out.println("cf2結(jié)果->"+cf2.get());
}

測試結(jié)果:

9114db50-648a-11ed-8abf-dac502259ad0.png 914c3bd6-648a-11ed-8abf-dac502259ad0.png

從上面代碼和測試結(jié)果我們發(fā)現(xiàn)thenApply和thenApplyAsync區(qū)別在于,使用thenApply方法時子任務(wù)與父任務(wù)使用的是同一個線程,而thenApplyAsync在子任務(wù)中是另起一個線程執(zhí)行任務(wù),并且thenApplyAsync可以自定義線程池,默認的使用ForkJoinPool.commonPool()線程池。

2. thenAccept和thenAcceptAsync

thenAccep表示某個任務(wù)執(zhí)行完成后執(zhí)行的動作,即回調(diào)方法,會將該任務(wù)的執(zhí)行結(jié)果即方法返回值作為入?yún)鬟f到回調(diào)方法中,無返回值。

測試代碼

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
return1;
});

CompletableFuturecf2=cf1.thenAccept((result)->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
});

//等待任務(wù)1執(zhí)行完成
System.out.println("cf1結(jié)果->"+cf1.get());
//等待任務(wù)2執(zhí)行完成
System.out.println("cf2結(jié)果->"+cf2.get());
}


publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
return1;
});

CompletableFuturecf2=cf1.thenAcceptAsync((result)->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
});

//等待任務(wù)1執(zhí)行完成
System.out.println("cf1結(jié)果->"+cf1.get());
//等待任務(wù)2執(zhí)行完成
System.out.println("cf2結(jié)果->"+cf2.get());
}

測試結(jié)果:

915c4ad0-648a-11ed-8abf-dac502259ad0.png 917f8ce8-648a-11ed-8abf-dac502259ad0.png從上面代碼和測試結(jié)果我們發(fā)現(xiàn)thenAccep和thenAccepAsync區(qū)別在于,使用thenAccep方法時子任務(wù)與父任務(wù)使用的是同一個線程,而thenAccepAsync在子任務(wù)中可能是另起一個線程執(zhí)行任務(wù),并且thenAccepAsync可以自定義線程池,默認的使用ForkJoinPool.commonPool()線程池。

3.thenRun和thenRunAsync

thenRun表示某個任務(wù)執(zhí)行完成后執(zhí)行的動作,即回調(diào)方法,無入?yún)ⅲ瑹o返回值。

測試代碼:

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
return1;
});

CompletableFuturecf2=cf1.thenRun(()->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
});

//等待任務(wù)1執(zhí)行完成
System.out.println("cf1結(jié)果->"+cf1.get());
//等待任務(wù)2執(zhí)行完成
System.out.println("cf2結(jié)果->"+cf2.get());
}

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
return1;
});

CompletableFuturecf2=cf1.thenRunAsync(()->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
});

//等待任務(wù)1執(zhí)行完成
System.out.println("cf1結(jié)果->"+cf1.get());
//等待任務(wù)2執(zhí)行完成
System.out.println("cf2結(jié)果->"+cf2.get());
}

測試結(jié)果:

919bd614-648a-11ed-8abf-dac502259ad0.png91aa1882-648a-11ed-8abf-dac502259ad0.png

從上面代碼和測試結(jié)果我們發(fā)現(xiàn)thenRun和thenRunAsync區(qū)別在于,使用thenRun方法時子任務(wù)與父任務(wù)使用的是同一個線程,而thenRunAsync在子任務(wù)中可能是另起一個線程執(zhí)行任務(wù),并且thenRunAsync可以自定義線程池,默認的使用ForkJoinPool.commonPool()線程池。

4.whenComplete和whenCompleteAsync

whenComplete是當某個任務(wù)執(zhí)行完成后執(zhí)行的回調(diào)方法,會將執(zhí)行結(jié)果或者執(zhí)行期間拋出的異常傳遞給回調(diào)方法,如果是正常執(zhí)行則異常為null,回調(diào)方法對應(yīng)的CompletableFuture的result和該任務(wù)一致,如果該任務(wù)正常執(zhí)行,則get方法返回執(zhí)行結(jié)果,如果是執(zhí)行異常,則get方法拋出異常。

測試代碼:

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
inta=1/0;
return1;
});

CompletableFuturecf2=cf1.whenComplete((result,e)->{
System.out.println("上個任務(wù)結(jié)果:"+result);
System.out.println("上個任務(wù)拋出異常:"+e);
System.out.println(Thread.currentThread()+"cf2dosomething....");
});

////等待任務(wù)1執(zhí)行完成
//System.out.println("cf1結(jié)果->"+cf1.get());
////等待任務(wù)2執(zhí)行完成
System.out.println("cf2結(jié)果->"+cf2.get());
}

測試結(jié)果:

91b85c44-648a-11ed-8abf-dac502259ad0.png

whenCompleteAsync和whenComplete區(qū)別也是whenCompleteAsync可能會另起一個線程執(zhí)行任務(wù),并且thenRunAsync可以自定義線程池,默認的使用ForkJoinPool.commonPool()線程池。

5.handle和handleAsync

跟whenComplete基本一致,區(qū)別在于handle的回調(diào)方法有返回值。

測試代碼:

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
//inta=1/0;
return1;
});

CompletableFuturecf2=cf1.handle((result,e)->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
System.out.println("上個任務(wù)結(jié)果:"+result);
System.out.println("上個任務(wù)拋出異常:"+e);
returnresult+2;
});

//等待任務(wù)2執(zhí)行完成
System.out.println("cf2結(jié)果->"+cf2.get());
}

測試結(jié)果 :

91dba032-648a-11ed-8abf-dac502259ad0.png

基于 Spring Cloud Alibaba + Gateway + Nacos + RocketMQ + Vue & Element 實現(xiàn)的后臺管理系統(tǒng) + 用戶小程序,支持 RBAC 動態(tài)權(quán)限、多租戶、數(shù)據(jù)權(quán)限、工作流、三方登錄、支付、短信、商城等功能

  • 項目地址:https://github.com/YunaiV/yudao-cloud
  • 視頻教程:https://doc.iocoder.cn/video/

三、多任務(wù)組合處理

1. thenCombine、thenAcceptBoth 和runAfterBoth

這三個方法都是將兩個CompletableFuture組合起來處理,只有兩個任務(wù)都正常完成時,才進行下階段任務(wù)。

區(qū)別:thenCombine會將兩個任務(wù)的執(zhí)行結(jié)果作為所提供函數(shù)的參數(shù),且該方法有返回值;thenAcceptBoth同樣將兩個任務(wù)的執(zhí)行結(jié)果作為方法入?yún)?,但是無返回值;runAfterBoth沒有入?yún)ⅲ矝]有返回值。注意兩個任務(wù)中只要有一個執(zhí)行異常,則將該異常信息作為指定任務(wù)的執(zhí)行結(jié)果。

測試代碼:

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
return1;
});

CompletableFuturecf2=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
return2;
});

CompletableFuturecf3=cf1.thenCombine(cf2,(a,b)->{
System.out.println(Thread.currentThread()+"cf3dosomething....");
returna+b;
});

System.out.println("cf3結(jié)果->"+cf3.get());
}

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
return1;
});

CompletableFuturecf2=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
return2;
});

CompletableFuturecf3=cf1.thenAcceptBoth(cf2,(a,b)->{
System.out.println(Thread.currentThread()+"cf3dosomething....");
System.out.println(a+b);
});

System.out.println("cf3結(jié)果->"+cf3.get());
}

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf1dosomething....");
return1;
});

CompletableFuturecf2=CompletableFuture.supplyAsync(()->{
System.out.println(Thread.currentThread()+"cf2dosomething....");
return2;
});

CompletableFuturecf3=cf1.runAfterBoth(cf2,()->{
System.out.println(Thread.currentThread()+"cf3dosomething....");
});

System.out.println("cf3結(jié)果->"+cf3.get());
}

測試結(jié)果:

91f51922-648a-11ed-8abf-dac502259ad0.png9211a330-648a-11ed-8abf-dac502259ad0.png

92274e9c-648a-11ed-8abf-dac502259ad0.png 2.applyToEither、acceptEither和runAfterEither

這三個方法和上面一樣也是將兩個CompletableFuture組合起來處理,當有一個任務(wù)正常完成時,就會進行下階段任務(wù)。

區(qū)別:applyToEither會將已經(jīng)完成任務(wù)的執(zhí)行結(jié)果作為所提供函數(shù)的參數(shù),且該方法有返回值;acceptEither同樣將已經(jīng)完成任務(wù)的執(zhí)行結(jié)果作為方法入?yún)?,但是無返回值;runAfterEither沒有入?yún)?,也沒有返回值。

測試代碼:

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf1dosomething....");
Thread.sleep(2000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
return"cf1任務(wù)完成";
});

CompletableFuturecf2=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf2dosomething....");
Thread.sleep(5000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
return"cf2任務(wù)完成";
});

CompletableFuturecf3=cf1.applyToEither(cf2,(result)->{
System.out.println("接收到"+result);
System.out.println(Thread.currentThread()+"cf3dosomething....");
return"cf3任務(wù)完成";
});

System.out.println("cf3結(jié)果->"+cf3.get());
}


publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf1dosomething....");
Thread.sleep(2000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
return"cf1任務(wù)完成";
});

CompletableFuturecf2=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf2dosomething....");
Thread.sleep(5000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
return"cf2任務(wù)完成";
});

CompletableFuturecf3=cf1.acceptEither(cf2,(result)->{
System.out.println("接收到"+result);
System.out.println(Thread.currentThread()+"cf3dosomething....");
});

System.out.println("cf3結(jié)果->"+cf3.get());
}

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf1dosomething....");
Thread.sleep(2000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
System.out.println("cf1任務(wù)完成");
return"cf1任務(wù)完成";
});

CompletableFuturecf2=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf2dosomething....");
Thread.sleep(5000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
System.out.println("cf2任務(wù)完成");
return"cf2任務(wù)完成";
});

CompletableFuturecf3=cf1.runAfterEither(cf2,()->{
System.out.println(Thread.currentThread()+"cf3dosomething....");
System.out.println("cf3任務(wù)完成");
});

System.out.println("cf3結(jié)果->"+cf3.get());
}

測試結(jié)果:

92418438-648a-11ed-8abf-dac502259ad0.png925d7cc4-648a-11ed-8abf-dac502259ad0.png

從上面可以看出cf1任務(wù)完成需要2秒,cf2任務(wù)完成需要5秒,使用applyToEither組合兩個任務(wù)時,只要有其中一個任務(wù)完成時,就會執(zhí)行cf3任務(wù),顯然cf1任務(wù)先完成了并且將自己任務(wù)的結(jié)果傳值給了cf3任務(wù),cf3任務(wù)中打印了接收到cf1任務(wù)完成,接著完成自己的任務(wù),并返回cf3任務(wù)完成;acceptEither和runAfterEither類似,acceptEither會將cf1任務(wù)的結(jié)果作為cf3任務(wù)的入?yún)?,但cf3任務(wù)完成時并無返回值;runAfterEither不會將cf1任務(wù)的結(jié)果作為cf3任務(wù)的入?yún)?,它是沒有任務(wù)入?yún)?,?zhí)行完自己的任務(wù)后也并無返回值。

2. allOf / anyOf

allOf:CompletableFuture是多個任務(wù)都執(zhí)行完成后才會執(zhí)行,只有有一個任務(wù)執(zhí)行異常,則返回的CompletableFuture執(zhí)行g(shù)et方法時會拋出異常,如果都是正常執(zhí)行,則get返回null。

anyOf :CompletableFuture是多個任務(wù)只要有一個任務(wù)執(zhí)行完成,則返回的CompletableFuture執(zhí)行g(shù)et方法時會拋出異常,如果都是正常執(zhí)行,則get返回執(zhí)行完成任務(wù)的結(jié)果。

測試代碼:

publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf1dosomething....");
Thread.sleep(2000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
System.out.println("cf1任務(wù)完成");
return"cf1任務(wù)完成";
});

CompletableFuturecf2=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf2dosomething....");
inta=1/0;
Thread.sleep(5000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
System.out.println("cf2任務(wù)完成");
return"cf2任務(wù)完成";
});

CompletableFuturecf3=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf2dosomething....");
Thread.sleep(3000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
System.out.println("cf3任務(wù)完成");
return"cf3任務(wù)完成";
});

CompletableFuturecfAll=CompletableFuture.allOf(cf1,cf2,cf3);
System.out.println("cfAll結(jié)果->"+cfAll.get());
}


publicstaticvoidmain(String[]args)throwsExecutionException,InterruptedException{
CompletableFuturecf1=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf1dosomething....");
Thread.sleep(2000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
System.out.println("cf1任務(wù)完成");
return"cf1任務(wù)完成";
});

CompletableFuturecf2=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf2dosomething....");
Thread.sleep(5000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
System.out.println("cf2任務(wù)完成");
return"cf2任務(wù)完成";
});

CompletableFuturecf3=CompletableFuture.supplyAsync(()->{
try{
System.out.println(Thread.currentThread()+"cf2dosomething....");
Thread.sleep(3000);
}catch(InterruptedExceptione){
e.printStackTrace();
}
System.out.println("cf3任務(wù)完成");
return"cf3任務(wù)完成";
});

CompletableFuturecfAll=CompletableFuture.anyOf(cf1,cf2,cf3);
System.out.println("cfAll結(jié)果->"+cfAll.get());
}

		

測試結(jié)果:

9278b9a8-648a-11ed-8abf-dac502259ad0.png928fa848-648a-11ed-8abf-dac502259ad0.png

審核編輯 :李倩


聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 接口
    +關(guān)注

    關(guān)注

    33

    文章

    9603

    瀏覽量

    157673
  • 線程
    +關(guān)注

    關(guān)注

    0

    文章

    510

    瀏覽量

    20874

原文標題:一網(wǎng)打盡:異步神器 CompletableFuture 萬字詳解!

文章出處:【微信號:芋道源碼,微信公眾號:芋道源碼】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。

收藏 人收藏
加入交流群
微信小助手二維碼

掃碼添加小助手

加入工程師交流群

    評論

    相關(guān)推薦
    熱點推薦

    同步復(fù)位和異步復(fù)位到底該用哪個

    做FPGA/數(shù)字IC設(shè)計的,平時寫得最多的可能就是復(fù)位邏輯了。但你有沒有這種感覺:看別人代碼,有的用同步復(fù)位,有的用異步復(fù)位,有的又搞什么"異步復(fù)位同步釋放"——到底該用哪個?
    的頭像 發(fā)表于 04-22 09:42 ?413次閱讀
    同步復(fù)位和<b class='flag-5'>異步</b>復(fù)位到底該用哪個

    淘寶券后價異步數(shù)據(jù)

    淘寶 券后價異步數(shù)據(jù) ,核心是 非阻塞、批量、延遲獲取 商品券后價(原價 - 優(yōu)惠券),適合大規(guī)模商品監(jiān)控、比價、選品場景。淘寶官方無直接 “券后價異步接口”,需通過 官方 API 組合 + 異步
    的頭像 發(fā)表于 03-25 15:39 ?163次閱讀

    低功耗電源管理神器——LTC2935 電壓監(jiān)視器詳解

    低功耗電源管理神器——LTC2935 電壓監(jiān)視器詳解 在電子設(shè)備的電源管理領(lǐng)域,低功耗、高精度、多功能的電壓監(jiān)視和復(fù)位功能是至關(guān)重要的。今天,我們就來深入探討一下 Linear Technology
    的頭像 發(fā)表于 02-27 11:45 ?437次閱讀

    詳解SRC4192和SRC4193:專業(yè)音頻領(lǐng)域的異步采樣率轉(zhuǎn)換器

    詳解SRC4192和SRC4193:專業(yè)音頻領(lǐng)域的異步采樣率轉(zhuǎn)換器 在專業(yè)音頻和廣播應(yīng)用的領(lǐng)域中,對音頻信號處理的精度和靈活性要求極高。SRC4192和SRC4193這兩款異步采樣率轉(zhuǎn)換器(ASRC
    的頭像 發(fā)表于 02-03 16:00 ?792次閱讀

    詳解TL16C550C:高性能異步通信芯片的卓越之選

    詳解TL16C550C:高性能異步通信芯片的卓越之選 在電子工程師的日常工作中,選擇合適的通信芯片對于實現(xiàn)穩(wěn)定、高效的異步通信至關(guān)重要。今天,我們就來深入探討一款功能強大的異步通信芯片
    的頭像 發(fā)表于 01-04 16:20 ?591次閱讀

    異步電機零速滿轉(zhuǎn)矩輸出問題詳解

    異步電機在零速狀態(tài)下實現(xiàn)滿轉(zhuǎn)矩輸出是工業(yè)驅(qū)動領(lǐng)域的核心技術(shù)難題,其本質(zhì)在于如何克服低速時轉(zhuǎn)子電阻變化、磁鏈觀測誤差等固有特性。當電機靜止時,傳統(tǒng)V/f控制方式因定子電阻壓降導(dǎo)致氣隙磁通衰減,轉(zhuǎn)矩輸出
    的頭像 發(fā)表于 01-04 07:36 ?718次閱讀

    李飛飛萬字長文:空間智能是AI的下一個十年

    1950年,當計算機不過是自動化算術(shù)和簡單邏輯的代名詞時,艾倫·圖靈提出了一個至今仍有回響的問題:機器能思考嗎?他以非凡
    的頭像 發(fā)表于 11-19 21:20 ?1427次閱讀
    李飛飛<b class='flag-5'>萬字</b>長文:空間智能是AI的下一個十年

    萬字長文AI智能體:17種體架構(gòu)詳細實現(xiàn)

    數(shù)據(jù)科學(xué)AI智能體領(lǐng)域發(fā)展迅猛,但許多資源仍然過于抽象和理論化。創(chuàng)建此項目的目的是為開發(fā)者、研究人員和AI愛好者提供一條結(jié)構(gòu)化、實用且深入的學(xué)習(xí)路徑,以掌握構(gòu)建智能系統(tǒng)的藝術(shù)。
    的頭像 發(fā)表于 11-07 13:16 ?782次閱讀
    <b class='flag-5'>萬字</b>長文AI智能體:17種體架構(gòu)詳細實現(xiàn)

    Redis Sentinel和Cluster模式如何選擇

    在我十年的運維生涯中,見過太多團隊在Redis集群方案選擇上踩坑。有的團隊盲目追求"高大上"的Cluster模式,結(jié)果運維復(fù)雜度爆表;有的團隊死守Sentinel不放,最后擴展性成了瓶頸。今天,我想通過這篇萬字長文,把我在生產(chǎn)環(huán)境中積累的經(jīng)驗全部分享給你。
    的頭像 發(fā)表于 09-08 09:31 ?786次閱讀

    3萬字長文!深度解析大語言模型LLM原理

    我們正在參加全球電子成就獎的評選,歡迎大家?guī)臀覀兺镀薄x謝支持本文轉(zhuǎn)自:騰訊技術(shù)工程作者:royceshao大語言模型LLM的精妙之處在于很好地利用數(shù)學(xué)解決了工業(yè)場景的問題,筆者基于過往工程經(jīng)驗繼續(xù)追本溯源,與騰訊學(xué)堂合作撰寫本文,嘗試讓人人都能懂大語言模型的基礎(chǔ)原理。1、大語言模型簡述截止到2025年“大模型”一般泛指“超大參數(shù)模型”,參數(shù)是指深度神經(jīng)
    的頭像 發(fā)表于 09-02 13:34 ?3623次閱讀
    3<b class='flag-5'>萬字</b>長文!深度解析大語言模型LLM原理

    萬字全文科普:什么是IP?

    半導(dǎo)體行業(yè)在一個復(fù)雜且快速發(fā)展的生態(tài)系統(tǒng)中運作,并由持續(xù)創(chuàng)新驅(qū)動。該生態(tài)系統(tǒng)的核心是半導(dǎo)體價值鏈,它包含幾個關(guān)鍵階段:芯片設(shè)計、晶圓制造、最終組裝和原材料采購。每個階段對于半導(dǎo)體器件的生產(chǎn)和功能都至關(guān)重要。IP提供商在這一框架中發(fā)揮著關(guān)鍵作用,尤其是在芯片設(shè)計階段,該階段是整個價值鏈的基礎(chǔ)。他們提供專業(yè)的尖端技術(shù),以增強創(chuàng)新、促進無縫集成、確保合規(guī)性并加快產(chǎn)
    的頭像 發(fā)表于 07-21 09:53 ?1356次閱讀
    <b class='flag-5'>萬字</b>全文科普:什么是IP?

    萬字長文】物聯(lián)網(wǎng)的激蕩二十年

    2005年11月,在突尼斯舉辦的信息社會世界峰會(WSIS)上,國際電信聯(lián)盟(ITU)發(fā)布了一份名為《ITU互聯(lián)網(wǎng)報告2005:物聯(lián)網(wǎng)》,正式向世人展示了什么是“物聯(lián)網(wǎng)(InternetofThings)”。雖然業(yè)界一致認為,1999年,麻省理工學(xué)院的KevinAshton首次提出”物聯(lián)網(wǎng)”這一術(shù)語,但僅僅只是一個理念,沒有成體系的解釋,也無法形成共識。而I
    的頭像 發(fā)表于 06-27 13:42 ?1756次閱讀
    【<b class='flag-5'>萬字</b>長文】物聯(lián)網(wǎng)的激蕩二十年

    (ST大賽三等獎作品)超聲波自拍神器實例項目

    (ST大賽三等獎作品)超聲波自拍神器電路圖:
    發(fā)表于 05-28 21:04

    MAX14830四通道串行UART,具有128FIFO技術(shù)手冊

    MAX14830是一款先進的四通道通用異步收發(fā)器(UART),每路UART帶有128先入/先出(FIFO)接收和發(fā)送緩存器,以及高速串行外設(shè)接口(SPI?)或I2C控制器接口。PLL和分數(shù)波特率發(fā)生器為波特率編程和參考時鐘選擇提供了極大靈活性。
    的頭像 發(fā)表于 05-22 10:14 ?1254次閱讀
    MAX14830四通道串行UART,具有128<b class='flag-5'>字</b>FIFO技術(shù)手冊

    MAX3109雙通道串行UART,帶有128FIFO技術(shù)手冊

    MAX3109先進的雙通道通用異步收發(fā)器(UART)具有128收發(fā)先進/先出(FIFO)堆棧和高速SPI?或I2C控制器接口。2倍速和4倍速模式允許工作在最高24Mbps數(shù)據(jù)速率。鎖相環(huán)(PLL)和分數(shù)波特率發(fā)生器允許靈活設(shè)置波特率、選擇參考時鐘。
    的頭像 發(fā)表于 05-22 09:26 ?1009次閱讀
    MAX3109雙通道串行UART,帶有128<b class='flag-5'>字</b>FIFO技術(shù)手冊
    高密市| 都江堰市| 武威市| 罗平县| 灵武市| 清水河县| 青岛市| 抚顺县| 十堰市| 云南省| 桦川县| 鄢陵县| 准格尔旗| 岳阳县| 大埔区| 巧家县| 安达市| 陆川县| 石河子市| 璧山县| 札达县| 额济纳旗| 兴业县| 镇远县| 临桂县| 修文县| 凭祥市| 南溪县| 衡阳县| 澄江县| 黎平县| 墨脱县| 新密市| 公安县| 庄河市| 盐亭县| 布尔津县| 于都县| 改则县| 凉城县| 洛扎县|