java.lang.Object
java.lang.Thread
de.seggebaeing.sqlanalyzer.logic.util.thread.WorkerThread
de.seggebaeing.sqlanalyzer.logic.util.thread.EvaluationThread
All Implemented Interfaces:
Runnable

public class EvaluationThread extends WorkerThread
Worker that evaluates GeneratedQuery instances in parallel using a StatementComparator.

Submits one task per query to a fixed thread pool (poolSize). Each task retries up to repCountIfFailure times until the comparator returns a numeric score (non-NaN). Progress is signaled via startedProgress/finishedProgress. If the comparator is an LLMComparator, a rate-limit reporter is registered. On full success, signalDone is invoked.

Threading: results are stored in a synchronized map; interruption is honored and cancels work. Read results via getResult() only after successful completion.

Since:
1.0
Author:
Felix Seggebäing
  • Constructor Details

    • EvaluationThread

      public EvaluationThread(int poolSize, int repCountIfFailure, Set<GeneratedQuery> gqs, StatementComparator comparator, Runnable signalDone, Runnable startedProgress, Runnable finishedProgress, Consumer<Instant> reportRetryIn)
      Constructs an evaluation worker thread.
      Parameters:
      poolSize - number of parallel subworkers to use
      repCountIfFailure - maximum attempts per query until a non-NaN score is returned
      gqs - set of generated queries to evaluate
      comparator - comparator used to compute similarity scores
      signalDone - callback invoked on successful completion (may be null)
      startedProgress - callback invoked when a task starts
      finishedProgress - callback invoked when a task finishes
      reportRetryIn - optional consumer for retry instants when using an LLMComparator
      Implementation Note:
      Thread is named "Evaluation-Worker-<n>" using an atomic counter.
  • Method Details

    • run

      public void run()
      Executes evaluation by dispatching one task per GeneratedQuery to a fixed thread pool.

      If the comparator is an LLMComparator, registers the rate-limit reporter. Initializes a synchronized score map, submits all tasks, then shuts down the pool and awaits completion (practically unbounded). On full success, invokes signalDone if non-null. On interruption, cancels subworkers, logs, and re-interrupts the thread; on timeout, logs an error.

      Specified by:
      run in interface Runnable
      Specified by:
      run in class WorkerThread
    • getResult

      public Map<GeneratedQuery,Double> getResult()
      Returns the computed similarity scores per GeneratedQuery.

      Behavior is undefined if called before the worker has completed successfully.

      Specified by:
      getResult in class WorkerThread
      Returns:
      a synchronized map of queries to their scores
      Implementation Note:
      The returned map is a Collections.synchronizedMap; synchronize on it when iterating.