共 10 篇文章 |
|
我们刚才使用thenCompose()将两个CompletableFuture结合了起来,并且一个CompletableFuture的运算结果将作为第二个CompletableFuture的入参。@Test public void combine(){ Shop shop = new Shop("沃尔玛"); Future<Double> futurePrice = CompletableFuture.supplyAsync(() -> shop.getPrice("iphoneX")) .thenC... 阅21 转0 评0 公众公开 20-02-05 20:23 |
@Test public void findPrices(){ BestFinder bestFinder = new BestFinder();} @Test public void findPricesParallel(){ BestFinder bestFinder = new BestFinder();明智的选择是创建了一个配有线程池的执行器,线程池中线程的数目取决于你的应用需要处理的负担,但是你该如何选择合适的线程数目呢?现在我们知道了如何用CompletableFuture提... 阅14 转1 评0 公众公开 20-02-05 20:22 |
空闲线程存活60s。默认情况下,在创建了线程池后,线程池中的线程数为0。直到线程池中的线程数不大于corePoolSize,即当线程池中的线程数大于corePoolSize时,如果一个线程空闲的时间达到keepAliveTime,则会终止,直到线程池中的线程数不超过corePoolSize。但是如果调用了allowCoreThreadTimeOut(boolean)方法,在线程池中的线程数不大于coreP... 阅11 转0 评0 公众公开 20-02-05 20:21 |
JVM中存在一个主存区(Main Memory或Java Heap Memory),Java中所有变量都是存在主存中的,对于所有线程进行共享,而每个线程又存在自己的工作内存(Working Memory),工作内存中保存的是主存中某些变量的拷贝,线程对所有变量的操作并非发生在主存区,而是发生在工作内存中,而线程之间是不能直接相互访问,变量在程序中的传递,是依赖主存来完成的。... 阅24 转0 评0 公众公开 20-02-05 20:21 |
阅627 转0 评0 公众公开 20-02-04 20:51 |
阅637 转0 评0 公众公开 20-02-04 19:31 |
阅821 转0 评0 公众公开 20-02-04 19:11 |
guava中对future的增强就是在addListener这个方法上进行了各种各样的封装,所以addListener是核心方法void addListener(Runnable listener, Executor executor);jdk原生FutureTask类是对Future接口的实现,guava中ListenableFutureTask继承了FutureTask并实现了ListenableFuture,guava异步回调最简单的使用: 阅188 转0 评0 公众公开 20-02-04 18:10 |