Does Java 7 fork / join support thread execution in a separate CPU

Recently, I learned about the forv / join Java 7 platform. I found out that it can be useful for problems related to share and win.

The question is, does the environment protect thread execution on individual processors? Or is it possible for the event to indicate which threads I create using parallel package classes to run on separate processors available on my server?

+4
source share
3 answers

It will be built on standard JVM concurrency primitives, in which case they will (ultimately) be scheduled for real OS threads. You cannot guarantee that the OS scheduler plans to schedule threads in a separate CPUS, although in most cases this is pretty likely.

Trying to guess what the parallel scheduler is going to do at runtime is a really bad idea. Just assume that you can use no more than as many processors as there are active threads, and don’t try to repeat the runtime check if you are not trying to perform a certain type of very low level optimization.

+5
source

Does the infrastructure provide thread execution on separate processors?

No. There is no guarantee.

Or is it possible for the event to indicate the threads that I create using parallel package classes to run on separate processors available on my server?

Do not use standard Java libraries. Theoretically, anything is possible (to the limit of what the OS allows) if you are ready to delve into your own JVM layers. But you will have a lot of unnecessary work / pain.

My advice:

  • You probably do not need this level of control. (IMO), it is likely that the default behavior of the native thread scheduler is "good enough" to achieve satisfactory performance.

  • If you really need this level of control, you would be better off using a different programming language; that is, where you can interact directly with the OS host thread scheduler. You might even need a different operating system ...

+2
source

At least he will do his best. The fork / join structure is designed to use multiple processors. By default, ForkJoinPool is created with the number of worker threads equal to the number of processors.

+1
source

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


All Articles