The Java Fork-Join Pool Framework Flashcards

1
Q

The _ provides a high performance, parallel, fine-grained task execution framework for Java programs.

A

ForkJoinPool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A ForkJoinPool distinguishes itself from other types of ExecutorService primarily through its use of _: every thread in the pool seeks to locate and perform tasks that have been submitted to the pool or generated by other currently active tasks (ultimately blocking and waiting for work if none is available).

A

work-stealing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

It provides a parallel computing engine for many higher-level frameworks.

A

ForkJoinPool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

_ is a feature of Java 8 and higher, meant for utilizing multiple cores of the processor.

A

Java Parallel Streams

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Java Parallel Streams is a feature of _ and higher, meant for utilizing multiple cores of the processor.

A

Java 8

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Using the _, we can divide chunks of code into streams that execute in parallel on multiple cores. The final result is the grouping of the different results (outcomes).

A

parallel stream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A _ is a flow of objects that supports various functions and is intended to produce a reliable output.

A

parallel stream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

_ in Java is simply a wrapper around a data source, allowing us to perform bulk operations on the data in a convenient way.

A

Stream

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

_ enable us to execute code in parallel on separate cores. The final result is the combination of each outcome. However, the order of execution is out of our control. It may change every time we run the program.

A

Parallel streams

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Parallel streams enable us to execute code in parallel on _ cores. The final result is the combination of each outcome. However, the order of execution is out of our control. It may _ every time we run the program.

A

separate, change

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Parallel streams make use of the _ and its common pool of worker threads.

A

fork-join framework

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The fork-join framework was added to _ in Java 7 to handle task management between multiple threads.

A

java.util.concurrent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

By using the parallel stream, we can divide chunks of code into streams that execute in parallel on multiple cores. It is advisable to use parallel streams in such a case where the sequence of execution does not matter and the result will not be affected. Also, notable that the state of one element does not affect the other as well as the source of the data remains unaffected.

A

Noted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

_ is an Executor Service implementation.

A

Fork-Join Pool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

_ is the basis for Java Executor framework sublasses.

A

Executor Service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The Java ExecutorService
* is a construct that allows you to pass a task to be executed by a thread asynchronously.
* creates and maintains a reusable pool of threads for executing submitted tasks.
* also manages a queue, which is used when there are more tasks than the number of threads in the pool and there is a need to queue up tasks until there is a free thread available to execute the task.

A

Noted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The Java ExecutorService is a _ that allows you to pass a task to be executed by a thread _.

A

construct, asynchronously

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

The Java ExecutorService creates and maintains a reusable _ for executing submitted tasks.

A

pool of threads

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The Java ExecutorService manages a _, which is used when there are more tasks than the number of threads in the pool and there is a need to queue up tasks until there is a free thread available to execute the task.

A

queue

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Other implementations Executor Service of execute runnables and callables.

A

AbstractExecutorService

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

_ defines methods that enable non-ForkJoinTask clients to process ForkJoinTasks.

A

ForkJoinPool

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

ForkJoinPool executes _.

A

fork/join tasks

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

ForkJoinPool

These methods insert new _ onto a shared queue used to feed _ queues managed by worker threads.

A

tasks, unshared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

A ForkJoinTask associates a chunk of data along with a computation on that data, which enables _.

A

fine-grained parallelism

25
Q

A program is broken down to a large number of small tasks.

A

Fine-grained parallelism

26
Q

Fine-Grained Parallelism
* These tasks are assigned individually to many processors.
* The amount of work associated with a parallel task is low and the work is evenly distributed among the processors.
* fine-grained parallelism facilitates load balancing.

A

Noted

27
Q

A ForkJoinTask is _ weight than a Java thread.

A

lighter

28
Q

A _ number of ForkJoinTasks can thus run in a _ number of worker threads in a fork-join pool.

A

large, small

29
Q

A ForkJoinTask has two methods that control parallel processing/merging:

A

fork() - Arranges to asynchronously execute this task in the appropriate pool.

join() - Returns the result of the computation when it is done.

30
Q

fork() arranges to _ execute a ForkJoinTask in the appropriate pool.

A

asynchronously

31
Q

join() returns the _ of the computation when it is done.

A

result

32
Q

Programs rarely use the ForkJoinTask class directly but instead extend one of its subclasses & override compute()

**RecursiveAction
**RecursiveTask
**CountedCompleter

A

Noted

33
Q

Each worker thread in a fork-join pool maintains its own _.

A

double ended queue (deque)

34
Q

The Java fork-join framework implements this deque via the _ class.

A

WorkQueue

35
Q

A worker threads processes its own deque in _ order by popping (sub)-task from of its own deque.

A

LIFO (Last In First Out)

36
Q

To maximize core utilization, idle worker threads _ work from the tail of busy threads’ deques

A

steal

37
Q

Idle worker threads steal work from the tail of busy threads’ deques to _ core utilization.

A

maximize

38
Q

Tasks are stolen in _ order since an older stolen task may provide a larger unit of work.

A

FIFO

39
Q

Java Fork-Join Framework Internals enable further recursive _ by the stealing thread.

A

decompositions

40
Q

The _ deque that implements work-stealing minimizes locking contention.

A

WorkQueue deque

41
Q

The Workqueue deque that implements work-stealing _ locking contention.

A

minimizes

42
Q

_ and _ are called by the owning worker thread. These operations use wait-free “compare-and-swap” (CAS) operations.

A

push(), pop()

43
Q

Adds an element to the top of the stack.

A

push()

44
Q

Removes the topmost element from the stack.

A

pop()

45
Q

Push() and pop() use wait-free _ operations.

A

“compare-and-swap” (CAS)

46
Q

_ may be called from another worker thread to steal a (sub-)task.

A

Poll()

47
Q

Poll may be called from another worker thread to _ a (sub-)task.

A

steal

48
Q

A _ is used for asynchronous programming.

A

CompletableFuture

49
Q

A CompletableFuture is used for _ programming.

A

asynchronous

50
Q

Asynchronous programming means writing _ code.

A

non-blocking

51
Q

CompletableFuture runs a task on a _ thread from the main application thread and notifies the main thread about its progress, completion, or failure.

A

separate

52
Q

In CompletableFuture, the main thread does not _ or _ for the completion of the task.

A

block, wait

53
Q

In CompletableFuture, other tasks are executed in _.

A

parallel

54
Q

_ improves the performance of the program.

A

Parallelism

55
Q

CONCLUSION

  • The ForkJoinPool framework in Java offers a powerful and effective approach to parallel programming, especially for algorithms that utilize divide-and-conquer strategies. By using the strategy work-stealing algorithm, it efficiently coordinates task execution among several threads, enhancing resource use and boosting performance.
  • Using the fork/join framework can speed up the processing of large tasks, but to achieve this outcome, we should follow some guidelines:
    Use as few thread pools as possible. In most cases, the best decision is to use one thread pool per application or system.
    Use the default common thread pool if no specific tuning is needed.
    Use a reasonable threshold for splitting ForkJoinTask into subtasks.
    Avoid any blocking in ForkJoinTasks.
A

Noted

56
Q

Fork/Join Framework Guidelines

Use as _ thread pools as possible. In most cases, the best decision is to use one thread pool per application or system.

A

few

57
Q

Fork/Join Framework Guidelines

Use the _ common thread pool if no specific tuning is needed.

A

default

58
Q

Fork/Join Framework Guidelines

Use a reasonable threshold for splitting _ into subtasks.

A

ForkJoinTask

59
Q

Fork/Join Framework Guidelines

Avoid any _ in ForkJoinTasks.

A

blocking