Skip to content

Commit

Permalink
docs: parallelStream hyperlink add
Browse files Browse the repository at this point in the history
  • Loading branch information
masiljangajji committed Nov 14, 2024
1 parent ba55162 commit e624a68
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ A [`map`][map], being a key-value pair structure, is suitable for recording freq
If the data being counted has a limited range (e.g., `Characters` or `Integers`), an `int[] array` or [`List<Integer>`][list] can be used to record frequencies.

Parallel processing typically takes place in a multi-[`thread`][thread] environment.
The Java 8 [`stream`][stream] API provides methods that make parallel processing easier, including the `parallelStream()` method.
With `parallelStream()`, developers can use the [`ForkJoinPool`][ForkJoinPool] model for workload division and parallel execution, without the need to manually manage threads or create custom thread pools.
The Java 8 [`stream`][stream] API provides methods that make parallel processing easier, including the [`parallelStream()`][stream] method.
With [`parallelStream()`][stream], developers can use the [`ForkJoinPool`][ForkJoinPool] model for workload division and parallel execution, without the need to manually manage threads or create custom thread pools.

The [`ForkJoinPool`][ForkJoinPool] class, optimized for dividing and managing tasks, makes parallel processing efficient.
However, `parallelStream()` uses the common [`ForkJoinPool`][ForkJoinPool] by default, meaning multiple `parallelStream` instances share the same thread pool unless configured otherwise.
However, [`parallelStream()`][stream] uses the common [`ForkJoinPool`][ForkJoinPool] by default, meaning multiple [`parallelStream`][stream] instances share the same thread pool unless configured otherwise.

As a result, parallel streams may interfere with each other when sharing this thread pool, potentially affecting performance.
Although this doesn’t directly impact solving the Parallel Letter Frequency problem, it may introduce issues when thread pool sharing causes conflicts in other applications.
Expand Down Expand Up @@ -130,7 +130,7 @@ For more information, check the [`fork/join` approach][approach-fork-join].

## Which approach to use?

When tasks are simple or do not require a dedicated thread pool (such as in this case), the `parallelStream` approach is recommended.
When tasks are simple or do not require a dedicated thread pool (such as in this case), the [`parallelStream`][stream] approach is recommended.
However, if the work is complex or there is a need to isolate thread pools from other concurrent tasks, the [`ForkJoinPool`][ForkJoinPool] approach is preferable.

[thread]: https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html
Expand Down

0 comments on commit e624a68

Please sign in to comment.