Class ThreadLocalPropertiesManager
java.lang.Object
com.shaft.properties.internal.ThreadLocalPropertiesManager
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 Summary
Modifier and TypeMethodDescriptionstatic voidclear()Clears all thread-local property overrides for the current thread.static PropertiesReturns a merged view of system properties and thread-local overrides for the current thread.static PropertiesReturns the live thread-local overrides map for the current thread.static StringgetProperty(String key) Returns the effective value for the given property key by checking the current thread's overrides first and falling back to the corresponding system property.static voidsetProperty(String key, String value) Sets a property override for the current thread only.
-
Method Details
-
setProperty
-
getProperty
Returns the effective value for the given property key by checking the current thread's overrides first and falling back to the corresponding system property. This is the single-key equivalent ofgetEffectiveProperties()and should be used in place ofSystem.getProperty(key)wherever SHAFT configuration values are read, so that per-thread overrides are honoured.- Parameters:
key- the property key- Returns:
- the thread-local value if set, otherwise the system property value,
or
nullif neither is set
-
getOverrides
Returns the live thread-local overrides map for the current thread. This map is passed toConfigFactory.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
-
getEffectiveProperties
Returns a merged view of system properties and thread-local overrides for the current thread. Thread-local overrides take precedence over system properties.This method should be used wherever code previously called
System.getProperties()to look up SHAFT configuration values, so that per-thread overrides set via theSHAFT.PropertiesAPI are visible.- Returns:
- a new
Propertiesinstance containing all system properties with thread-local overrides applied on top
-
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@BeforeClassruns) to prevent stale overrides from a previously executed test class on the same pooled thread.
-