0

As I understand it, the join() method merge/composes/combines the results from all subtasks. A simple example I saw was summing the numbers from 1 to N and the subtasks would simply sum a range of such numbers -- obtaining the final result very naturally involved summing each subtask's result to indeed get the right answers.

However, what if the results could not be combined via simple addition? Is there a way of specifying both a custom class for a result and a custom method of merging these results?

4
  • Are you referring to the Baeldung example? Commented Mar 27, 2024 at 8:30
  • no, to mkyong's: mkyong.com/java/java-fork-join-framework-examples Commented Mar 27, 2024 at 9:55
  • Have you tried to consider what happens if you change the + operator in that code to something else? Do you think if you change it to - or * or / or something else entirely, it still performs addition? Commented Mar 27, 2024 at 11:13
  • @JörgWMittag i understand the answer and marked it as accepted. Commented Mar 27, 2024 at 12:37

1 Answer 1

7

join does not combine any results. It simply awaits and retrieves the result of the single task you call it on. Any combining of results from multiple tasks happens in code you write after the join call. Thus, you can use whatever code you want to combine results in whatever fashion you need.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.