Class ThreadLocalPropertiesManager

java.lang.Object
com.shaft.properties.internal.ThreadLocalPropertiesManager

public final class ThreadLocalPropertiesManager extends Object
Manages per-thread property overrides for SHAFT properties.

When a property is set via the SHAFT.Properties API, it is stored in a thread-local map so that each test thread has its own isolated configuration. This prevents cross-thread contamination during parallel test execution.

Call clear() after each test class lifecycle completes to reset per-thread overrides and prevent stale state when thread pools reuse threads.

  • Method Details

    • setProperty

      public static void setProperty(String key, String value)
      Sets a property override for the current thread only. Does not affect other threads or global system properties.
      Parameters:
      key - the property key
      value - the property value
    • getOverrides

      public static Properties getOverrides()
      Returns the live thread-local overrides map for the current thread. This map is passed to ConfigFactory.create() as the highest-priority property source so that any overrides set by the current thread take precedence over system properties and file-based properties.
      Returns:
      the current thread's property overrides
    • clear

      public static void clear()
      Clears all thread-local property overrides for the current thread. Should be called at the start of each new test class lifecycle (before @BeforeClass runs) to prevent stale overrides from a previously executed test class on the same pooled thread.