Is there any library like Intel TBB in Java which support Parallelism.
Perhaps you could clarify what exactly you are looking for
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.
This is what the concurrency libraries have done since 1998 and were made part of Java 5.0 in 2004.
EDIT: Say you want a thread pool which can use all the logical processors on your system.
ExecutorService es = Executors.newFixedThreadPool(
Runtime.getRuntime().availableProcessors);
// to add a number of tasks
for(int i=0; i<numberOfTasks; i++) {
es.submit(new Callable<ResultType>() {
public ResultType call() {
return doWork(i);
}
}
}
This will performs doWork on each free thread.
Looking at its features they look very familiar.
I had a look at some of the low level optimisations like thread aware memory allocation. In Java this is called TLAB (Thread Local Allocation Buffers) and is transparent. I suspect most Java developers don't even know they exist.
Results and Exceptions are captured for you in a Future object which you can inspect later.
You can have "condition variables" such as CountdownLatch or 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:
Java's ConcurrentHashMap supports the ConcurrentMap and Map interfaces, permits concurrent insertion and traversal and does not expose any locks. ;) It is at least 9 years old so you know it should be robust and stable.
There is a PriorityQueue which you can use in you thread pool if you wish.
there is a good book for this topic :
Java Concurrency in Practice
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With