Class ContextAwareRunnable

java.lang.Object
com.axelor.concurrent.ContextAwareRunnable
All Implemented Interfaces:
Runnable

public final class ContextAwareRunnable extends Object implements Runnable
A wrapper around a Runnable that enables execution within a context-aware environment. This propagates contextual information such as tenant and user details, as well as the base URL and language preferences, to the execution thread of the task.
  • Method Details

    • of

      public static ContextAwareRunnable of(Runnable task)
      Creates a new instance of ContextAwareRunnable for the given Runnable task.
      Parameters:
      task - the Runnable task to be executed within a context-aware environment
      Returns:
      a ContextAwareRunnable instance wrapping the provided task
    • of

      public static ContextAwareRunnable of(Runnable task, boolean withTransaction)
      Creates a new instance of ContextAwareRunnable for the given Runnable task.
      Parameters:
      task - the Runnable task to be executed within a context-aware environment
      withTransaction - whether the task should be executed within a transactional scope
      Returns:
      a ContextAwareRunnable instance wrapping the provided task
    • run

      public void run()
      Executes a task within a specific context state. The method ensures that the provided context is applied during the task execution and restores the previous context upon completion. Optionally, the task can be executed within a transactional scope if enabled.
      Specified by:
      run in interface Runnable