+ All Categories
Home > Documents > Key Methods in the Java Recursive Action & RecursiveTask ...

Key Methods in the Java Recursive Action & RecursiveTask ...

Date post: 09-Jan-2022
Category:
Upload: others
View: 2 times
Download: 0 times
Share this document with a friend
20
Key Methods in the Java Recursive Action & RecursiveTask Subclasses Douglas C. Schmidt [email protected] www.dre.vanderbilt.edu/~schmidt Professor of Computer Science Institute for Software Integrated Systems Vanderbilt University Nashville, Tennessee, USA
Transcript
Page 1: Key Methods in the Java Recursive Action & RecursiveTask ...

Key Methods in the Java Recursive

Action & RecursiveTask Subclasses

Douglas C. [email protected]

www.dre.vanderbilt.edu/~schmidt

Professor of Computer Science

Institute for Software

Integrated Systems

Vanderbilt University

Nashville, Tennessee, USA

Page 2: Key Methods in the Java Recursive Action & RecursiveTask ...

2

• Recognize the key methods in the ForkJoinPool class

• Recognize the key methods in the ForkJoinTask class

• Recognize the key methods in the RecursiveAction & RecursiveTaskclasses

Learning Objectives in this Part of the Lesson

Page 3: Key Methods in the Java Recursive Action & RecursiveTask ...

3

Key Methods in the Java RecursiveAction

Page 4: Key Methods in the Java Recursive Action & RecursiveTask ...

4

• RecursiveAction extends ForkJoinTask & does not return a result

See docs.oracle.com/javase/8/docs/api/java/util/concurrent/RecursiveAction.html

Key Methods in Java RecursiveActionabstract class RecursiveAction

extends ForkJoinTask<Void> {

...

Page 5: Key Methods in the Java Recursive Action & RecursiveTask ...

5

• RecursiveAction extends ForkJoinTask & does not return a result

• Subclasses override compute() to perform task’s main computation

abstract class RecursiveAction

extends ForkJoinTask<Void> {

protected abstract Void

compute();

...

See docs.oracle.com/javase/8/docs/api/java/util/concurrent/RecursiveTask.html#compute

Key Methods in Java RecursiveAction

Page 6: Key Methods in the Java Recursive Action & RecursiveTask ...

6

• RecursiveAction extends ForkJoinTask & does not return a result

• Subclasses override compute() to perform task’s main computation

• If data size is below a certain threshold perform work directly

abstract class RecursiveAction

extends ForkJoinTask<Void> {

protected abstract Void

compute();

...

Key Methods in Java RecursiveAction

Page 7: Key Methods in the Java Recursive Action & RecursiveTask ...

7

• RecursiveAction extends ForkJoinTask & does not return a result

• Subclasses override compute() to perform task’s main computation

• If data size is below a certain threshold perform work directly

• If data size is large, split work into smaller sub-tasks that are fork()’d to run in parallel

abstract class RecursiveAction

extends ForkJoinTask<Void> {

protected abstract Void

compute();

...

Key Methods in Java RecursiveAction

Page 8: Key Methods in the Java Recursive Action & RecursiveTask ...

8

• RecursiveAction extends ForkJoinTask & does not return a result

• Subclasses override compute() to perform task’s main computation

• If data size is below a certain threshold perform work directly

• If data size is large, split work into smaller sub-tasks that are fork()’d to run in parallel

• These smaller sub-tasks are join()’d,but a result is not returned directly

• e.g., results may be stored in an array

abstract class RecursiveAction

extends ForkJoinTask<Void> {

protected abstract Void

compute();

...

Key Methods in Java RecursiveAction

Page 9: Key Methods in the Java Recursive Action & RecursiveTask ...

9

• RecursiveAction extends ForkJoinTask & does not return a result

• Subclasses override compute() to perform task’s main computation

• The fork-join framework callsexec() to execute the task

abstract class RecursiveAction

extends ForkJoinTask<Void> {

protected abstract Void

compute();

protected final boolean exec(){

compute();

return true;

}

...

See docs.oracle.com/javase/8/docs/api/java/util/concurrent/RecursiveTask.html#exec

Key Methods in Java RecursiveAction

exec() is an abstract method in ForkJoinTask that’s overridden in RecursiveAction

Page 10: Key Methods in the Java Recursive Action & RecursiveTask ...

10

• RecursiveAction extends ForkJoinTask & does not return a result

• Subclasses override compute() to perform task’s main computation

• The fork-join framework callsexec() to execute the task

abstract class RecursiveAction

extends ForkJoinTask<Void> {

protected abstract Void

compute();

protected final boolean exec(){

compute();

return true;

}

...

See en.wikipedia.org/wiki/Template_method_pattern

Key Methods in Java RecursiveAction

exec() is a template method & compute() is a hook method

Page 11: Key Methods in the Java Recursive Action & RecursiveTask ...

11

• RecursiveAction extends ForkJoinTask & does not return a result

• Subclasses override compute() to perform task’s main computation

• The fork-join framework callsexec() to execute the task

abstract class RecursiveAction

extends ForkJoinTask<Void> {

protected abstract Void

compute();

protected final boolean exec(){

compute();

return true;

}

...

Key Methods in Java RecursiveAction

The result of compute() is not stored for subsequent access

Page 12: Key Methods in the Java Recursive Action & RecursiveTask ...

12

Key Methods in the Java RecursiveTask

Page 13: Key Methods in the Java Recursive Action & RecursiveTask ...

13

• RecursiveTask extends ForkJoinTaskto return a result

See docs.oracle.com/javase/8/docs/api/java/util/concurrent/RecursiveTask.html

Key Methods in Java RecursiveTaskabstract class RecursiveTask<V>

extends ForkJoinTask<V> {

...

Page 14: Key Methods in the Java Recursive Action & RecursiveTask ...

14

• RecursiveTask extends ForkJoinTaskto return a result

• Subclasses override compute() to perform task’s main computation

abstract class RecursiveTask<V>

extends ForkJoinTask<V> {

protected abstract V

compute();

...

See docs.oracle.com/javase/8/docs/api/java/util/concurrent/RecursiveTask.html#compute

Key Methods in Java RecursiveTask

Page 15: Key Methods in the Java Recursive Action & RecursiveTask ...

15

• RecursiveTask extends ForkJoinTaskto return a result

• Subclasses override compute() to perform task’s main computation

• If data size is below a certain threshold perform work directly

abstract class RecursiveTask<V>

extends ForkJoinTask<V> {

protected abstract V

compute();

...

Key Methods in Java RecursiveTask

Page 16: Key Methods in the Java Recursive Action & RecursiveTask ...

16

• RecursiveTask extends ForkJoinTaskto return a result

• Subclasses override compute() to perform task’s main computation

• If data size is below a certain threshold perform work directly

• If data size is large, split work into smaller sub-tasks that are fork()’d to run in parallel

abstract class RecursiveTask<V>

extends ForkJoinTask<V> {

protected abstract V

compute();

...

Key Methods in Java RecursiveTask

Page 17: Key Methods in the Java Recursive Action & RecursiveTask ...

17

• RecursiveTask extends ForkJoinTaskto return a result

• Subclasses override compute() to perform task’s main computation

• If data size is below a certain threshold perform work directly

• If data size is large, split work into smaller sub-tasks that are fork()’d to run in parallel

• Results of these smaller sub-tasks are join()’d into a merged result

abstract class RecursiveTask<V>

extends ForkJoinTask<V> {

protected abstract V

compute();

...

Key Methods in Java RecursiveTask

Page 18: Key Methods in the Java Recursive Action & RecursiveTask ...

18

• RecursiveTask extends ForkJoinTaskto return a result

• Subclasses override compute() to perform task’s main computation

• The fork-join framework callsexec() to execute the task

abstract class RecursiveTask<V>

extends ForkJoinTask<V> {

protected abstract V

compute();

V result;

protected final boolean exec(){

result = compute();

return true;

}

...

See docs.oracle.com/javase/8/docs/api/java/util/concurrent/RecursiveTask.html#exec

Key Methods in Java RecursiveTask

exec() is an abstract (template) method in ForkJoinTask that’s overridden in RecursiveTask

Page 19: Key Methods in the Java Recursive Action & RecursiveTask ...

19

• RecursiveTask extends ForkJoinTaskto return a result

• Subclasses override compute() to perform task’s main computation

• The fork-join framework callsexec() to execute the task

abstract class RecursiveTask<V>

extends ForkJoinTask<V> {

protected abstract V

compute();

V result;

protected final boolean exec(){

result = compute();

return true;

}

...

Key Methods in Java RecursiveTask

The result of compute() is stored for subsequent access

Page 20: Key Methods in the Java Recursive Action & RecursiveTask ...

20

End of Key Methods in the Java RecursiveAction

& RecursiveTask Subclasses


Recommended