-
public class ThreadUtilsThread 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.
-
-
Field Summary
Fields Modifier and Type Field Description private final CoroutineDispatcherMainDispatcherprivate final CoroutineDispatcherIODispatcherprivate final CoroutineDispatcherCPUDispatcherprivate final CoroutineDispatcherDatabaseDispatcherprivate final CoroutineScopeGlobalMainScopeprivate final CoroutineScopeGlobalIOScopepublic final static ThreadUtilsINSTANCE
-
Method Summary
Modifier and Type Method Description final CoroutineScopecreateScope(String tag, CoroutineDispatcher dispatcher)Create a component-scoped coroutine scope with proper error handling and lifecycle management. final CoroutineScopecreateMainScope(String tag)Convenience method to create a main-thread component scope (uses Main dispatcher). final CoroutineScopecreateIOScope(String tag)Convenience method to create a background component scope (uses IO dispatcher). final <T extends Any> TexecuteWithTimeout(Long timeoutMs, CoroutineContext context, SuspendFunction1<CoroutineScope, T> block)Execute a suspend function with timeout and error handling. final CoroutineDispatchergetMainDispatcher()final CoroutineDispatchergetIODispatcher()final CoroutineDispatchergetCPUDispatcher()final CoroutineDispatchergetDatabaseDispatcher()final CoroutineScopegetGlobalMainScope()final CoroutineScopegetGlobalIOScope()-
-
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 millisecondscontext- coroutine context to useblock- the suspend function to execute
-
getMainDispatcher
final CoroutineDispatcher getMainDispatcher()
-
getIODispatcher
final CoroutineDispatcher getIODispatcher()
-
getCPUDispatcher
final CoroutineDispatcher getCPUDispatcher()
-
getDatabaseDispatcher
final CoroutineDispatcher getDatabaseDispatcher()
-
getGlobalMainScope
final CoroutineScope getGlobalMainScope()
-
getGlobalIOScope
final CoroutineScope getGlobalIOScope()
-
-
-
-