博客
关于我
了解一下CompletionService的submit(Runnable task, V result)方法
阅读量:223 次
发布时间:2019-02-28

本文共 781 字,大约阅读时间需要 2 分钟。

示例demo:

public class CompletionServiceDemo {       public static void main(String[] args) throws ExecutionException, InterruptedException {           ExecutorService pool = Executors.newFixedThreadPool(3);        ExecutorCompletionService
completionService = new ExecutorCompletionService(pool); Future
future = completionService.submit(new Runnable() { @Override public void run() { try { TimeUnit.SECONDS.sleep(5); } catch (InterruptedException e) { e.printStackTrace(); } } }, "我是默认值"); System.out.println(future.get()); pool.shutdown(); }}

运行结果:

在这里插入图片描述

总结

从运行结果可以看出,这个方法实际作用就是为Runnable类型的任务设置一个默认值返回。

转载地址:http://ljjp.baihongyu.com/

你可能感兴趣的文章
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中json_extract的使用方法
查看>>
mysql中kill掉所有锁表的进程
查看>>
mysql中like % %模糊查询
查看>>
MySql中mvcc学习记录
查看>>
mysql中null和空字符串的区别与问题!
查看>>