Class MultiThreadingWarningUtil

java.lang.Object
com.okta.sdk.client.MultiThreadingWarningUtil

public class MultiThreadingWarningUtil extends Object
Utility class to detect and warn about multi-threaded usage of the Okta SDK.

The Okta SDK stores per-thread pagination state keyed by thread ID. When multiple threads use the same ApiClient instance, this can lead to:

  • Unexpected pagination behavior (threads interfering with each other's pagination state)
  • Thread safety issues in thread pool environments
  • Difficult-to-debug race conditions

This utility tracks which threads access the SDK and emits warnings when multi-threaded usage is detected. It is designed to have minimal performance impact and will only log warnings, not prevent multi-threaded usage.

  • Constructor Details

    • MultiThreadingWarningUtil

      public MultiThreadingWarningUtil()
  • Method Details

    • recordThreadAccess

      public void recordThreadAccess()
      Records that the current thread has accessed the SDK and checks if warnings should be emitted.

      This method should be called at key points in the SDK lifecycle where thread state is being used (e.g., when storing or retrieving pagination state).

    • getUniqueThreadCount

      public int getUniqueThreadCount()
      Returns the number of unique threads that have accessed this ApiClient instance.
      Returns:
      the count of unique threads
    • reset

      public void reset()
      Resets all tracking state. This is primarily useful for testing.

      WARNING: This method should not be called in production code. It exists solely for testing purposes.