Class UnitsOfWork

java.lang.Object
com.kingsrook.qqq.backend.core.instrumentation.UnitsOfWork

public final class UnitsOfWork extends Object
Opens and closes UnitOfWorks on the current thread. Units nest: the outermost unit owns every statement run while it is open (a process run inside an HTTP request belongs to that request; a scheduled job's process belongs to the job). Only the outermost unit's end is reported to listeners. Scopes do nothing (and return a shared no-op) while no statement listener is registered.
 try(UnitsOfWork.Scope scope = UnitsOfWork.begin(UnitOfWorkKind.SCHEDULED_JOB, processName)) { ... }
 
Units are per thread: work handed to another thread is not part of the unit (statements there are still attributed by process through the action stack).
  • Method Details

    • begin

      public static UnitsOfWork.Scope begin(UnitOfWorkKind kind, String name)
      Begin a unit (or a nested scope inside the open one). Close the returned scope exactly once, in a finally block or try-with-resources.
    • current

      public static UnitOfWork current()
      The outermost open unit on this thread, or null.
    • reset

      public static void reset()
      Drop any unit left open on this thread (for thread pools, before a new request), without reporting it.