Skip to content
Preview · sample content · Explore all pages

Build an in-memory task deque in Java

Last updated: 28 Sept 20263 min read
tutorial
By AITrove Editorial

An in-memory task deque holds pending work at endpoints and loses that work when its process exits.

Scope

Build a command-line tool that accepts add, urgent, next, list, and quit. Store task descriptions in a Deque<String>. add appends to the tail, urgent inserts at the head, and next polls the head.

Acceptance checks

  • Reject empty task descriptions.
  • Keep two equal descriptions as distinct pending tasks unless deduplication is explicitly required.
  • Show an empty result without calling removeFirst on an empty deque.
  • Document the loss of pending work on restart.
  • Compare an ArrayDeque implementation with a LinkedList implementation through the same Deque contract.

Design review

Endpoint operations are the appropriate contract here. No caller needs get(index), so exposing List would add operations without a requirement. A durable version needs identifiers, storage, retry state, and a defined policy for interrupted work.

Connected lessons

Continue with Java LinkedList: operations, internals and failure cases, Java LinkedList quiz.

Common Mistakes

This project is a learning tool, not a production job scheduler. Adding a second worker introduces coordination questions that a change of class name cannot solve.

java
linkedlist-project
Storage details