Principle:A616567126 GPT WEB JAVA Task Queueing
| Knowledge Sources | |
|---|---|
| Domains | Distributed_Systems, Concurrency |
| Last Updated | 2026-10-13 00:00 GMT |
Overview
Pattern that decouples task submission from execution by placing tasks into a queue, allowing controlled sequential or parallel processing with backpressure management.
Description
Task queueing separates the act of requesting work from the act of performing it. Producers submit tasks to a queue, and consumers process them at their own pace. This decoupling provides backpressure (rejecting tasks when the queue is full), ordering guarantees, and allows the processing rate to differ from the submission rate.
In this repository, two queueing systems exist:
- Redis-backed queue for Stable Diffusion:
QueueUtiluses a Redis list (user_queue) with FIFO semantics. A scheduled task (MyTask) polls the queue every 5 seconds and processes the head item. - Thread pool queue for Midjourney:
DiscordInstanceImplusesThreadPoolTaskExecutorwith a bounded queue. Tasks are submitted to the thread pool and executed with per-account concurrency limits.
Usage
Use this principle when:
- Processing takes longer than the client can wait (async processing)
- Needing to limit concurrency per resource (e.g., one Discord account)
- Requiring backpressure when the system is overloaded
Theoretical Basis
FIFO Queue with Backpressure:
# Abstract algorithm (NOT real implementation)
def add_to_queue(task):
if queue.size() >= MAX_SIZE:
raise QueueFullError()
queue.push_right(task)
def process_queue():
if queue.size() > 0:
task = queue.peek(0)
try:
result = execute(task)
queue.remove(task)
except Exception:
refund_credits(task.user)
queue.remove(task)
Key Properties:
- FIFO ordering: First-in, first-out via
redisTemplate.opsForList().rightPush() - Bounded capacity:
CommonConst.QUEUE_SIZElimits queue length - Duplicate detection:
getPosition()checks if identical request already queued - Atomic processing:
synchronizedoncreateImageprevents race conditions
Practical Guide
For Stable Diffusion:
QueueUtil.addUserToQueue(value)pushes serialized request to Redis listMyTask.run()(every 5s) reads the head item, calls SD WebUI API, and removes itQueueUtil.getPosition(value)lets clients poll their position in the queueSdController.getQueue()returns queue state (1=queuing with position, 2=generating with progress)
For Midjourney:
DiscordInstanceImpl.submitTask()saves the task and submits toThreadPoolTaskExecutor- If the thread pool queue is full,
RejectedExecutionExceptiontriggers task removal executeTask()runs the Discord API call and waits for WSS response
Related Pages
Implemented By
- Implementation:A616567126_GPT_WEB_JAVA_QueueUtil
- Implementation:A616567126_GPT_WEB_JAVA_DiscordInstanceImpl
- Implementation:A616567126_GPT_WEB_JAVA_MyTask
- Implementation:A616567126_GPT_WEB_JAVA_SdController