Parallelism in Java

Is there any library like Intel TBB in Java that supports Parallelism?

+4
source share
6 answers

Perhaps you could clarify what exactly you are looking for

Intel® Threading Building Blocks (Intel TBB) offers a rich and comprehensive approach to expressing parallelism in a C ++ program. This is a library that helps you take advantage of multi-core processors without being a thread expert. Intel TBB is not just a thread replacement library. It is a high-level, task-based parallelism that abstracts platform details and flow mechanisms for scalability and performance.

This is what concurrency libraries have done since 1998 and became part of Java 5.0 in 2004.

EDIT: Suppose you need a thread pool that can use all 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 do doWork for each free stream.

Looking at their features, they look very familiar.

I looked at some of the low-level optimizations, such as thread-supported memory allocation. In Java, this is called TLAB (Streaming Local Distribution Buffers) and transparent. I suspect that most Java developers do not even know that they exist.

Results and exceptions are captured for you in the Future object, which you can check later.

You may have "condition variables" such as CountdownLatch or CyclicBarrier

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

  • Interface very similar to C ++ 0x unordered_map
  • It allows for simultaneous insertion and crawl.
  • No lock is opened by the interface. An implementation may use locks internally, but a lock is never displayed in a way that can contribute to a deadlock. It may contain locks inside, but never call custom code.

Java ConcurrentHashMap supports the ConcurrentMap and Map interfaces, allows simultaneous insertion and bypass, and does not provide any locks;) It's at least 9 years old, so you know that it must be reliable and stable.

There is a PriorityQueue that you can use in your thread pool if you want.

+8
source

There is a good book for this topic:

 Java Concurrency in Practice 

Java Concurrency in Practice

+6
source

It is available in the java.util.concurrent package since Java5.

This edition included a major overhaul of the Java memory model to simplify the foundation of concurrent programming and solve known problems. In Java, concurrency is designed into the language from the very beginning, and not just added later to the library.

+4
source

Take a look at akka , which provides a concurrency infrastructure using Actors and transactional software memory. Of course, this just creates blocks, you still need to write some parallel code, but it gets a little easier.

+1
source

Check out the java.util.concurrent package. It has a whole bunch of classes that are useful for parallel programming.

By the way, you should consider accepting some answers. 15 questions without accepted answers do not allow people to answer your questions.

0
source

Some of you are asking about the difference between concurrency and parallelism. Compatibility means different programs that simulate work at the same time, and the scheduler decides which one works. Parallelism means that one program is divided into tasks and those tasks that are performed simultaneously in different kernels to solve the problem. When these tasks are collected for resources with other programs (we have more tasks than kernels), then we have concurrency and Parallelism at the same time. Conditions during the race are a less difficult part in parallelism, the big problem is finding a good way to decompose the problem correctly in order to get good results. Very fine-grained decomposition has drawbacks (overhead), but coarse-grained Parallelism (mono capture) also has drawbacks (you do not use all the processing power available on the computer). You should find a medium term term, this implies the performance of some optimization tasks (math)

0
source

Source: https://habr.com/ru/post/1334364/


All Articles