Package 

Object ThreadUtils


  • 
    public class ThreadUtils
    
                        

    Thread management utilities for the CloudX SDK.

    Provides optimized thread pools and executors for different types of operations, ensuring efficient resource usage and proper thread lifecycle management.

    • Method Detail

      • createScope

         final CoroutineScope createScope(String tag, CoroutineDispatcher dispatcher)

        Create a component-scoped coroutine scope with proper error handling and lifecycle management.

        Use this for components that need to cancel operations when destroyed (e.g., BannerManager, AdapterDelegate, timers). Each component gets its own isolated scope with SupervisorJob to prevent one failure from affecting other operations within the component.

        Parameters:
        tag - Component name for logging (e.g.
        dispatcher - Coroutine dispatcher to use (defaults to Main for UI components)
      • createMainScope

         final CoroutineScope createMainScope(String tag)

        Convenience method to create a main-thread component scope (uses Main dispatcher). Use for UI-related components like ad managers, UI controllers, etc.

      • createIOScope

         final CoroutineScope createIOScope(String tag)

        Convenience method to create a background component scope (uses IO dispatcher). Use for background components like trackers, network managers, etc.

      • executeWithTimeout

         final <T extends Any> T executeWithTimeout(Long timeoutMs, CoroutineContext context, SuspendFunction1<CoroutineScope, T> block)

        Execute a suspend function with timeout and error handling.

        Parameters:
        timeoutMs - timeout in milliseconds
        context - coroutine context to use
        block - the suspend function to execute