差異處
這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
java:java:java8:concurrent:blockingoperationwithcompletablefuture:blocking_inside_cf [2019/01/13 16:10] tony [How to resolve?] |
java:java:java8:concurrent:blockingoperationwithcompletablefuture:blocking_inside_cf [2023/06/25 09:48] (目前版本) |
||
---|---|---|---|
行 39: | 行 39: | ||
@Test | @Test | ||
- | public void testSendSync(){ | + | public void testSendAsync(){ |
- | CompletableFuture<Response> sendSync = CompletableFuture.supplyAsync(()->{ | + | CompletableFuture<Response> sendAsync = CompletableFuture.supplyAsync(()->{ |
dumpCurrentThreadName("supplyAsync"); | dumpCurrentThreadName("supplyAsync"); | ||
return launchTaskWithAuxThread(()->new BlockingJob().invoke()); | return launchTaskWithAuxThread(()->new BlockingJob().invoke()); | ||
行 53: | 行 53: | ||
}, es); | }, es); | ||
- | sendSync.join(); | + | sendAsync.join(); |
} | } | ||
</code> | </code> | ||
行 74: | 行 74: | ||
Note. 我的範例程式只是實現的方法之一,應要根據需求做調整。 例如原始投影片中,是透過responseReceived.completeAsync讓工作回到compose之後繼續往下處理。 | Note. 我的範例程式只是實現的方法之一,應要根據需求做調整。 例如原始投影片中,是透過responseReceived.completeAsync讓工作回到compose之後繼續往下處理。 | ||
===== Reference ===== | ===== Reference ===== | ||
- | * [[https://qconsf.com/sf2017/system/files/presentation-slides/cf.pdf|Asynchronous API with | + | * [[https://qconsf.com/sf2017/system/files/presentation-slides/cf.pdf|Asynchronous API with CompletableFuture - Performance Tips and Tricks]] |
- | CompletableFuture - Performance Tips and Tricks]] | + | * Java Concurrency In Practice, 11.6. Reducing Context Switch overhead. |
====== ====== | ====== ====== |