Question

I've started to use fj JAVA framework.
As I understand it just divides big task like algorithm computation and divides it into small threads.
The question is if it worth to use this framework on a single processor machine.
Thanks

Was it helpful?

Solution 2

As written in the oracle documentation JAVA FORK/JOIN:

The fork/join framework is an implementation of the ExecutorService interface that helps you take advantage of multiple processors. It is designed for work that can be broken into smaller pieces recursively. The goal is to use all the available processing power to enhance the performance of your application.

So it's main goal is multiple processors architecture.

OTHER TIPS

No.

A single processor (a single single-core processor) can't utilize multiple threads as it can only run one thread at a time. In fact, the overhead of thread managing will slow your computation down a bit.

Related: You can get the number of processors available to your application during runtime. See Runtime.availableProcessors().

Usually you use the number of processors at runtime to determine the configuration of your execution.

Even if you have a single core machine, you may have the ability to execute more than one thread at time, therefore you can leverage this using f.e. fork-join. If you really have just a single execution thread on your cpu, you will have a small overhead from using a multithreading framework compared to plain execution.

On the other hand: If you write your application on a single core machine and have no profit from it, you may be able to use a different machine later, or give the application to users which have multicore/threading machines. Without building the application again or change anything you can make use of that capabilities then.

So it really depends on the way you expect to use your application now - and in the future.

Multithreading is still useful on 1-core processors if there is significant amount of IO operations. Otherwise it can even hurt.

Each processor has a thread scheduler which can allocate time to one single thread to do its work. So if you have 100 threads and just one processor, the scheduler will just switch between those 100 threads. However, with that being said, there is no advantage in using multiple threads on a single processor because effectively what it happens, as I described, is that the scheduler just switches between threads really fast. Plus, context switching is quite slow from a CPU perspective.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top