Built from scratch. No Spring Boot. No shortcuts. Just raw Java engineering.
TaskQueue AI is not just another task scheduler demo. It is a fully functional, production-inspired backend system that combines deep Java concurrency engineering with a live AI brain that thinks about your tasks before they ever touch the queue.
Every piece of this system — the thread pool, the worker lifecycle, the priority engine, the REST API — was built by hand, using only Core Java. No frameworks. No magic. Pure engineering.
"Anyone can call
Executors.newFixedThreadPool(). We built what's inside it."
Most Java projects use ExecutorService and call it a day. We didn't. We implemented every component from scratch:
WorkerThread.java— extendsThread, continuously polls aPriorityBlockingQueue, handles its own retry logic and backoff delaysThreadPool.java— manages the lifecycle of N worker threads, tracks active count viaAtomicInteger, supports graceful shutdown that finishes in-flight tasks before rejecting new ones- No
Executors, noForkJoinPool, no framework abstractions — full visibility into every thread at every moment
This is the difference between using concurrency primitives and understanding them well enough to rebuild them.
Before any task enters the queue, it passes through our AIPrioritizationService — a real-time AI decision engine powered by the Groq API:
- Sends task metadata (type, deadline, payload) + current system state (queue depth, active threads, recent completion rate) to an LLM
- Receives a structured JSON response: suggested priority (1–10), recommendation (
URGENT/NORMAL/DEFER), estimated wait time, warnings - Automatically applies the decision — URGENT tasks jump to priority 10 and front of queue; DEFER tasks get flagged with warnings
- Every decision is logged in an
AIDecisionLogwith full traceability
This is not a UI gimmick. The AI actually changes execution order.
We built a cost-aware AI layer:
- AI is called once per task submission — never in polling loops
- Responses are cached for 30 seconds per task-type + queue-state combo to avoid duplicate calls
- Prompts are kept under 500 tokens by design
- If the Groq API is unavailable, the system falls back to a deterministic rule-based priority engine so nothing breaks
- Every API call logs token usage to the console for full credit visibility
Tasks don't just fail silently. Our execution engine:
- Catches exceptions during task execution
- Increments
retryCount, stores the failure reason in the task object - Re-queues the task with exponential backoff: delay = 2^retryCount seconds
- After
maxRetries(3) attempts, marks the task asFAILEDpermanently
This matches how real production systems handle transient failures.
The internal queue is a PriorityBlockingQueue<Task> with a custom comparator. Higher priority tasks always execute first — including when new high-priority tasks arrive while lower-priority ones are waiting. This is not a simple FIFO queue with a label. Priority is structurally enforced.
Every shared data structure was chosen and synchronized deliberately:
| Component | Thread-Safety Mechanism |
|---|---|
| Task storage | ConcurrentHashMap<UUID, Task> |
| Queue | PriorityBlockingQueue<Task> |
| Thread count | AtomicInteger |
| Task status updates | synchronized methods |
| AI decision log | ConcurrentHashMap |
No two threads can ever process the same task.