Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 9

Given:

class Sum extends RecursiveAction { //line n1 static final int THRESHOLD_SIZE = 3; int stIndex, lstIndex; int [ ] data; public Sum (int [ ]data, int start, int end) { this.data = data; this stIndex = start; this. lstIndex = end;

}

protected void compute ( ) {

int sum = 0;

if (lstIndex "" stIndex <= THRESHOLD_SIZE) {

for (int i = stIndex; i < lstIndex; i++) {

sum += data [i];

}

System.out.println(sum);

} else {

new Sum (data, stIndex + THRESHOLD_SIZE, lstIndex).fork( );

new Sum (data, stIndex,

Math.min (lstIndex, stIndex + THRESHOLD_SIZE)

).compute ();

}

}

}

and the code fragment:

ForkJoinPool fjPool = new ForkJoinPool ( );

int data [ ] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

fjPool.invoke (new Sum (data, 0, data.length));

and given that the sum of all integers from 1 to 10 is 55.

Which statement is true?

    Correct Answer: A

    The program utilizes the ForkJoin framework with a threshold to decide whether to compute the sum directly or to fork into smaller subtasks. Given the threshold size, the sum operation is divided among several tasks, and each task computes a partial sum and prints it. Therefore, the program prints several values that, when totaled, amount to 55.

Discussion
Ritesh_Option: A

Answer is A

PasciOption: A

if (lstIndex - stIndex <= THRESHOLD_SIZE)

asdfjhfgjuaDCVOption: A

A is the correct answer

Svetleto13Option: A

Answer is A,but if we do little change to this: if (lstIndex - stIndex >= THRESHOLD_SIZE) answer is B.

mevlt

If you use (lstIndex - stIndex >= THRESHOLD_SIZE) then you will not get the benefit of using parallel tasking which is the point of RecursiveAction and RecursiveTask.

InnovationOption: A

A is correct, tested

M_JawadOption: A

A is the correct answer