Skip to content

Commit 28a8ebc

Browse files
committed
docs: update markdown format and make it clear the method
1 parent 1f0531d commit 28a8ebc

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

exercises/practice/parallel-letter-frequency/.approaches/fork-join/content.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,19 @@ Using [`ConcurrentHashMap`][ConcurrentHashMap] ensures that frequency counting a
7070

7171
If there are no strings, a validation step prevents unnecessary processing.
7272

73-
A [`ForkJoinPool`][ForkJoinPool] is then created. The core of [`ForkJoinPool`][ForkJoinPool] is the Fork/Join mechanism, which divides tasks into smaller units and processes them in parallel.
73+
A [`ForkJoinPool`][ForkJoinPool] is then created.
7474

75-
THRESHOLD is the criterion for task division. If the range of texts exceeds the THRESHOLD, the task is divided into two subtasks, and [`invokeAll`][invokeAll](leftTask, rightTask) is called to execute both tasks in parallel.
75+
The core of [`ForkJoinPool`][ForkJoinPool] is the Fork/Join mechanism, which divides tasks into smaller units and processes them in parallel.
76+
77+
THRESHOLD is the criterion for task division.
78+
79+
If the range of texts exceeds the THRESHOLD, the task is divided into two subtasks, and [`invokeAll`][invokeAll](leftTask, rightTask) is called to execute both tasks in parallel.
7680

7781
Each subtask in LetterCountTask will continue calling compute() to divide itself further until the range is smaller than or equal to the threshold.
7882

79-
For tasks that are within the threshold, letter frequency is calculated. The [`Character.isAlphabetic`][isAlphabetic] method is used to identify all characters classified as alphabetic in Unicode, covering various languages like English, Korean, Japanese, Chinese, etc., returning true for alphabetic characters and false for numbers, special characters, spaces, and others.
83+
For tasks that are within the threshold, letter frequency is calculated.
84+
85+
The [`Character.isAlphabetic`][isAlphabetic] method is used to identify all characters classified as alphabetic in Unicode, covering various languages like English, Korean, Japanese, Chinese, etc., returning true for alphabetic characters and false for numbers, special characters, spaces, and others.
8086

8187
Additionally, since uppercase and lowercase letters are treated as the same character (e.g., A and a), each character is converted to lowercase.
8288

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

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

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

67
## General guidance
78

89
To count occurrences of items, a map data structure is often used, though arrays and lists can work as well.
910

10-
A map, being a key-value pair structure, is suitable for recording frequency by incrementing the value for each key.
11+
A [`map`][map], being a key-value pair structure, is suitable for recording frequency by incrementing the value for each key.
12+
13+
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.
14+
15+
Parallel processing typically takes place in a multi-[`thread`][thread] environment.
1116

12-
If the data being counted has a limited range (e.g., characters or integers), an int[] array or List<Integer> can be used to record frequencies.
17+
The Java 8 [`stream`][stream] API provides methods that make parallel processing easier, including the parallelStream() method.
1318

14-
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 model for workload division and parallel execution, without the need to manually manage threads or create custom thread pools.
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.
1520

1621
The [`ForkJoinPool`][ForkJoinPool] class, optimized for dividing and managing tasks, makes parallel processing efficient.
1722

18-
However, parallelStream() uses the common ForkJoinPool by default, meaning multiple parallelStream 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.
23+
However, parallelStream() uses the common ForkJoinPool by default, meaning multiple parallelStream instances share the same thread pool unless configured otherwise.
24+
25+
As a result, parallel streams may interfere with each other when sharing this thread pool, potentially affecting performance.
26+
27+
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.
1928

20-
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. Therefore, a custom ForkJoinPool approach is also provided below.
29+
Therefore, a custom ForkJoinPool approach is also provided below.
2130

2231
## Approach: `parallelStream`
2332

@@ -135,5 +144,7 @@ However, if the work is complex or there is a need to isolate thread pools from
135144
[thread]: https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html
136145
[stream]: https://docs.oracle.com/javase/8/docs/api/java/util/stream/package-summary.html
137146
[ForkJoinPool]: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ForkJoinPool.html
147+
[map]: https://docs.oracle.com/javase/8/docs/api/?java/util/Map.html
148+
[list]: https://docs.oracle.com/javase/8/docs/api/?java/util/List.html
138149
[approach-parallel-stream]: https://exercism.org/tracks/java/exercises/parallel-letter-frequency/approaches/parallel-stream
139150
[approach-fork-join]: https://exercism.org/tracks/java/exercises/parallel-letter-frequency/approaches/fork-join

exercises/practice/parallel-letter-frequency/.approaches/parallel-stream/content.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ Using [`ConcurrentHashMap`][ConcurrentHashMap] ensures that frequency counting a
3737

3838
If there are no strings to process, a validation step avoids unnecessary computation.
3939

40-
To calculate letter frequency, a parallel stream is used. The [`Character.isAlphabetic`][isAlphabetic] method identifies all characters classified as alphabetic in Unicode, covering characters from various languages like English, Korean, Japanese, Chinese, etc., returning true. Non-alphabetic characters, including numbers, special characters, and spaces, return false.
40+
To calculate letter frequency, a parallel stream is used.
41+
42+
The [`Character.isAlphabetic`][isAlphabetic] method identifies all characters classified as alphabetic in Unicode, covering characters from various languages like English, Korean, Japanese, Chinese, etc., returning true. Non-alphabetic characters, including numbers, special characters, and spaces, return false.
4143

4244
Since we treat uppercase and lowercase letters as the same character (e.g., A and a), characters are converted to lowercase.
4345

0 commit comments

Comments
 (0)