---
# System prepended metadata

title: 'Coding Task: Task Manager (Java)'

---

# Coding Task: Task Manager (Java)

In Livepeer we execute Tasks in Task Executor. This process follows two rules:

1. Execute the task only if Task Executor is not busy.
2. Tasks are executed sequentially.

Implement Task Manager with the mechanism to **queue, execute, and retry** tasks.

```java
public interface TaskExecutor {
    int getLastSeqN();
    boolean isBusy();
    void execute(Task task);
}

public class Task {
    private int seqN;

    // Task data, not related to this exercise
    private Object data;
}

public class TaskManager {
    public void execute(Task task, TaskExecutor executor) {
        // Naive implementation that executes each task, no matter of isBusy and seqN
        executor.execute(task);
    }
}
```