Package org.apache.sysds.runtime.controlprogram.parfor

# Class LocalTaskQueue<T>

java.lang.Object
org.apache.sysds.runtime.controlprogram.parfor.LocalTaskQueue<T>

Direct Known Subclasses:
  `SubscribableTaskQueue`

public class LocalTaskQueue<T> extends Object
This class provides a way of dynamic task distribution to multiple workers in local multi-threaded environments. Its main purpose is inter-thread communication for achieving dynamic load balancing. A good load balance between parallel workers is crucial with regard to the overall speedup of parallelization (see Amdahl's law). From a technical perspective, a thread monitor concept is used for blocking of waiting writers and readers. Synchronized writes and reads ensure that each task is only read by exactly one reader. Furthermore, the queue is implemented as a simple FIFO.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`MAX_SIZE`
`static final Object`
`NO_MORE_TASKS`

## Constructor Summary

Constructors
Constructor
Description
`LocalTaskQueue()`

## Method Summary

Modifier and Type
Method
Description
`void`
`closeInput()`
Synchronized (logical) insert of a NO_MORE_TASKS symbol at the end of the FIFO queue in order to mark that no more tasks will be inserted into the queue.
`T`
`dequeueTask()`
Synchronized read and delete from the top of the FIFO queue.
`void`
`enqueueTask(T t)`
Synchronized insert of a new task to the end of the FIFO queue.
`boolean`
`hasNext()`
`boolean`
`isProcessed()`
`void`
`propagateFailure(DMLRuntimeException failure)`
`String`
`toString()`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Field Details

### MAX_SIZE

public static final int MAX_SIZE

See Also:
  - Constant Field Values

### NO_MORE_TASKS

public static final Object NO_MORE_TASKS

## Constructor Details

### LocalTaskQueue

public LocalTaskQueue()

## Method Details

### enqueueTask

public void enqueueTask(T t) throws InterruptedException
Synchronized insert of a new task to the end of the FIFO queue.

Parameters:
  `t` - task
Throws:
  `InterruptedException` - if InterruptedException occurs

### dequeueTask

public T dequeueTask() throws InterruptedException
Synchronized read and delete from the top of the FIFO queue.

Returns:
  task
Throws:
  `InterruptedException` - if InterruptedException occurs

### hasNext

public boolean hasNext()

### closeInput

public void closeInput()
Synchronized (logical) insert of a NO_MORE_TASKS symbol at the end of the FIFO queue in order to mark that no more tasks will be inserted into the queue.

### isProcessed

public boolean isProcessed()

### propagateFailure

public void propagateFailure(DMLRuntimeException failure)

### toString

public String toString()

Overrides:
  `toString` in class `Object`