也许你可以澄清你究竟在寻找什么
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.