Module de.seggebaeing.sqlanalyzer
Class GenerationThread
java.lang.Object
java.lang.Thread
de.seggebaeing.sqlanalyzer.logic.util.thread.WorkerThread
de.seggebaeing.sqlanalyzer.logic.util.thread.GenerationThread
- All Implemented Interfaces:
Runnable
Worker that generates SQL queries by executing
Prompt × LLM
combinations,
optionally repeated, using a fixed-size pool of subworkers.
Responsibilities:
- Schedules jobs for each
Prompt × LLM × repetition
and computes a temperature value interpolated between each LLM’s min/max range. - Respects provider rate limits via
PromptAuthorizer
: waits before prompting and, onRateLimitException
, reports and registers the retryInstant
. - Emits per-LLM progress callbacks (
startedProgress
/finishedProgress
). - Collects results in a thread-safe set of
GeneratedQuery
and strips Markdown fences from returned SQL. - Honors interruption (cancels subworkers) and, on full success, invokes the
supplied
signalDone
callback.
poolSize
-bounded ExecutorService
.
The result set is synchronized; callers should only read it after the thread finished.- Since:
- 1.0
- Author:
- Felix Seggebäing
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Fields inherited from class de.seggebaeing.sqlanalyzer.logic.util.thread.WorkerThread
poolSize, signalDone
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionGenerationThread
(int poolSize, int repetitionCount, Collection<LLM> llms, Collection<Prompt> prompts, Runnable signalDone, Consumer<LLM> startedProgress, Consumer<LLM> finishedProgress, BiConsumer<LLM, Instant> rateLimitReporter) Constructs a generation worker thread. -
Method Summary
Modifier and TypeMethodDescriptionReturns the set of generated queries produced by this worker.void
run()
Executes generation by dispatchingPrompt × LLM × repetition
jobs to a fixed thread pool.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Constructor Details
-
GenerationThread
public GenerationThread(int poolSize, int repetitionCount, Collection<LLM> llms, Collection<Prompt> prompts, Runnable signalDone, Consumer<LLM> startedProgress, Consumer<LLM> finishedProgress, BiConsumer<LLM, Instant> rateLimitReporter) Constructs a generation worker thread.- Parameters:
poolSize
- number of parallel subworkers to userepetitionCount
- number of repetitions perPrompt × LLM
llms
- LLMs to use for generationprompts
- prompts to be combined with each LLMsignalDone
- callback invoked on successful completion (may benull
)startedProgress
- callback invoked when a subworker starts work for an LLMfinishedProgress
- callback invoked when a subworker finishes for an LLMrateLimitReporter
- callback to report rate-limit retry instants per LLM- Implementation Note:
- The thread name is assigned as
"Generation-Worker-<n>"
using an atomic counter.
-
-
Method Details
-
run
public void run()Executes generation by dispatchingPrompt × LLM × repetition
jobs to a fixed thread pool.Creates a
ExecutorService
withpoolSize
, submits one task per combination, then shuts down the pool and waits for completion. On full success (no timeout/interruption), invokessignalDone
. Honors interruption by cancelling subworkers.- Specified by:
run
in interfaceRunnable
- Specified by:
run
in classWorkerThread
- Implementation Note:
- Results are accumulated in a synchronized set; read them only after the thread finishes.
-
getResult
Returns the set of generated queries produced by this worker.Behavior is undefined if called before the thread has completed successfully.
- Specified by:
getResult
in classWorkerThread
- Returns:
- the (synchronized) result set of
GeneratedQuery
- Implementation Note:
- The returned set is a
Collections.synchronizedSet
; synchronize on it when iterating.
-