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

h5平台网站开发网站首页设计

h5平台网站开发,网站首页设计,扬州建设教育信息网站,郑州网站维护ListenableFuture可以允许你注册回调方法(callbacks),在运算(多线程执行)完成的时候进行调用, 或者在运算(多线程执行)完成后立即执行 import com.google.common.util.concurrent.*;import java.util.concurrent.Call…

ListenableFuture可以允许你注册回调方法(callbacks),在运算(多线程执行)完成的时候进行调用, 或者在运算(多线程执行)完成后立即执行

import com.google.common.util.concurrent.*;import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;/*** 如果需要所有的listenableFuture返回结果,可以使用countdownlatch,在Futures.addCallback的success里面把countdownlatch减1* 等countdownlatch=0的时候,所有的listenableFuture都计算完成*/
public class ListenableFutureLearn2 {public void test3() throws Exception {ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());// 执行任务final ListenableFuture<String> listenableFuture = executorService.submit(new Callable<String>() {public String call() throws Exception {for (int i = 0; i < 10000; i++) {System.out.println(i);}return "success";}});final ListenableFuture<String> listenableFuture2 = executorService.submit(new Callable<String>() {public String call() throws Exception {for (int i = 0; i < 10000; i++) {System.out.println(-i);}return "success";}});// 绑定任务以及回调函数Futures.addCallback(listenableFuture, new FutureCallback<String>() {@Overridepublic void onSuccess(String result) {String str = "";try {str = listenableFuture.get();} catch (InterruptedException e) {e.printStackTrace();} catch (ExecutionException e) {e.printStackTrace();}System.out.println("integer:" + str);System.out.println("result:" + result);}@Overridepublic void onFailure(Throwable t) {System.out.println("error" + t.getMessage());}}, MoreExecutors.directExecutor());Futures.addCallback(listenableFuture2, new FutureCallback<String>() {@Overridepublic void onSuccess(String result) {String str = "";try {str = listenableFuture.get();} catch (InterruptedException e) {e.printStackTrace();} catch (ExecutionException e) {e.printStackTrace();}System.out.println("integer:" + str);System.out.println("result:" + result);}@Overridepublic void onFailure(Throwable t) {System.out.println("error" + t.getMessage());}}, MoreExecutors.directExecutor());TimeUnit.MILLISECONDS.sleep(500);System.out.println("listenableFuture:" + listenableFuture.get());}public static void main(String[] args) throws Exception {new ListenableFutureLearn2().test3();}
}
http://www.yayakq.cn/news/244408/

相关文章:

  • 成为网站有哪些网址?九江的网站建设公司
  • 青岛建设银行官方网站嘉兴建网站
  • 温州 建网站专题定制网站建设
  • 一家专门做内部优惠的网站做网站郑州公司
  • 绍兴做网站的公司php网站api接口写法
  • 汽车销售网站建设网站建设玖金手指花总
  • 哈尔滨建设厅官方网站保定网站推广公司
  • 做佛像在什么网站发贴效果好点域名经纪公司推荐
  • 佛山网站排名推广滁州市建设工程管理处网站
  • 网站开发如何dw中小手重庆沙盘制作
  • 潍坊网站制作建设惠阳做网站公司
  • 安徽手机版建站系统高新营销型网站建设公司
  • 洛阳网络建站网站设计制作策划书
  • 佛山做外贸网站的wordpress 多媒体管理
  • 网站建设好后为什么要维护免费咨询图片大全
  • 杭州市建设工程检测协会网站招标网站的服务费怎么做分录
  • 有阿里云服务器 怎么做网站计算机网络服务
  • 渌口区市政建设局网站中山人才招聘网官网
  • 望牛墩镇做网站dede 网站地图
  • 南沙建设局网站工程私人承包协议书
  • wordpress站内统计插件各类微网站建设
  • 网站备案授权书模板汕头seo收费
  • 国外儿童社区网站模板下载全国公路建设信用网站
  • 广州微信网站设计制作iis网站无法启动
  • 网站专栏建设高端集团网站建设
  • 注册网站用户名怎么填写徐州建设工程交易网浙江公正
  • 电商网站运营怎么做网络营销与网络推广的异同
  • 学校网站的建设2022搜索引擎
  • 汽修网站怎么做上海市有哪些公司
  • 网站界面设计欣赏wordpress网站如何播放视频播放