logo

Crowdly

Browser

Додати до Chrome

Assuming MyTask is an abstract class that implements the ForkJoinTask interfac...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

Assuming MyTask is an abstract class that implements the ForkJoinTask interface, what statements about the following code are true? (Choose all that apply.)

import java.util.concurrent.*;

public class FindMin extends MyTask {

private Integer[] elements;

private int a;

private int b;

public FindMin(Integer[] elements, int a, int b) {

this.elements = elements;

this.a = a;

this.b = b;

}

public Integer compute() {

if ((b—a) < 2)

return Math.min(elements[a], elements[b]);

else {

int m = a + ((b—a) / 2);

System.out.println(a + "," + m + "," + b);

MyTask t1 = new FindMin(elements, a, m);

int result = t1.fork().join();

return Math.min(new FindMin(elements, m, b).compute(), result);

}

}

public static void main(String[] args) throws InterruptedException,

ExecutionException {

Integer[] elements = new Integer[] { 8, -3, 2, -54 };

MyTask task = new FindMin(elements, 0, elements.length—1);

ForkJoinPool pool = new ForkJoinPool(1);

Integer sum = pool.invoke(task);

System.out.println("Min: " + sum);

}

}

0%
100%
100%
100%
0%
100%
Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на dl.nure.ua?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome