java中并行_Java中的并行性

也许你可以澄清你究竟在寻找什么

Intel® Threading Building Blocks (Intel TBB) offers a rich and complete approach to expressing parallelism in a C++ program. It is a library that helps you take advantage of multi-core processor performance without having to be a threading expert. Intel TBB is not just a threads-replacement library. It represents a higher-level, task-based parallelism that abstracts platform details and threading mechanisms for scalability and performance.

这是自1998年以来并发库所做的,并且在2004年成为Java 5.0的一部分.

编辑:假设您想要一个可以使用系统上所有逻辑处理器的线程池.

ExecutorService es = Executors.newFixedThreadPool(

Runtime.getRuntime().availableProcessors);

// to add a number of tasks

for(int i=0; i

es.submit(new Callable() {

public ResultType call() {

return doWork(i);

}

}

}

这将在每个免费线程上执行doWork.

看看它的功能,它们看起来非常熟悉.

我看了一些低级优化,比如线程感知内存分配.在Java中,这称为TLAB(线程本地分配缓冲区)并且是透明的.我怀疑大多数Java开发人员甚至不知道它们存在.

在Future对象中捕获结果和异常,您可以稍后检查.

您可以拥有“条件变量”,例如CountdownLatch或CyclicBarrier

A new container mimicking C++ 0x unordered_map and based on a joint specification implemented by both Intel (TBB 3.0) and Microsoft (Visual Studio 2010). It has three advantages over the previous concurrent_hash_map:

>一个非常类似于C 0x unordered_map的接口

>它允许并发插入和遍历.

>界面没有暴露锁定.实现可以在内部使用锁,但锁定永远不会以可能导致死锁的方式暴露.它可能在内部持有锁,但从不在调用用户定义的代码时.

Java的ConcurrentHashMap支持ConcurrentMap和Map接口,允许并发插入和遍历,并且不暴露任何锁. ;)至少9岁,所以你知道它应该是健壮和稳定的.

如果您愿意,可以在线程池中使用PriorityQueue.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值