Skip to content

Commit d876b63

Browse files
committed
docs: update introduction
1 parent 72b1485 commit d876b63

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

exercises/practice/parallel-letter-frequency/.approaches/introduction.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,24 @@
11
# Introduction
22

33
There are multiple ways to solve the Parallel Letter Frequency problem.
4-
54
One approach is to use [`Stream.parallelStream`][stream], and another involves using [`ForkJoinPool`][ForkJoinPool].
65

76
## General guidance
87

98
To count occurrences of items, a map data structure is often used, though arrays and lists can work as well.
10-
119
A [`map`][map], being a key-value pair structure, is suitable for recording frequency by incrementing the value for each key.
12-
1310
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.
1411

1512
Parallel processing typically takes place in a multi-[`thread`][thread] environment.
16-
17-
The Java 8 [`stream`][stream] API provides methods that make parallel processing easier, including the parallelStream() method.
18-
19-
With parallelStream(), developers can use the ForkJoinPool model for workload division and parallel execution, without the need to manually manage threads or create custom thread pools.
13+
The Java 8 [`stream`][stream] API provides methods that make parallel processing easier, including the `parallelStream()` method.
14+
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.
2015

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

2519
As a result, parallel streams may interfere with each other when sharing this thread pool, potentially affecting performance.
26-
2720
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.
28-
29-
Therefore, a custom ForkJoinPool approach is also provided below.
21+
Therefore, a custom [`ForkJoinPool`][ForkJoinPool] approach is also provided below.
3022

3123
## Approach: `parallelStream`
3224

@@ -138,8 +130,8 @@ For more information, check the [`fork/join` approach][approach-fork-join].
138130

139131
## Which approach to use?
140132

141-
When tasks are simple or do not require a dedicated thread pool (such as in this case), the parallelStream approach is recommended.
142-
However, if the work is complex or there is a need to isolate thread pools from other concurrent tasks, the ForkJoinPool approach is preferable.
133+
When tasks are simple or do not require a dedicated thread pool (such as in this case), the `parallelStream` approach is recommended.
134+
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.
143135

144136
[thread]: https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html
145137
[stream]: https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html

0 commit comments

Comments
 (0)