pub struct ThreadPoolBuilder { /* private fields */ }Expand description
Builder for ThreadPool.
The default builder uses the available CPU parallelism as both core and maximum pool size, with an unbounded FIFO queue.
Implementations§
Source§impl ThreadPoolBuilder
impl ThreadPoolBuilder
Sourcepub fn core_pool_size(self, core_pool_size: usize) -> Self
pub fn core_pool_size(self, core_pool_size: usize) -> Self
Sets the core pool size.
A submitted task creates a new worker while the live worker count is below this value. Once the core size is reached, tasks are queued before the pool considers growing toward the maximum size.
§Parameters
core_pool_size- Core pool size.
§Returns
This builder for fluent configuration.
Sourcepub fn maximum_pool_size(self, maximum_pool_size: usize) -> Self
pub fn maximum_pool_size(self, maximum_pool_size: usize) -> Self
Sourcepub fn queue_capacity(self, capacity: usize) -> Self
pub fn queue_capacity(self, capacity: usize) -> Self
Sourcepub fn unbounded_queue(self) -> Self
pub fn unbounded_queue(self) -> Self
Sourcepub fn thread_name_prefix(self, prefix: &str) -> Self
pub fn thread_name_prefix(self, prefix: &str) -> Self
Sourcepub fn stack_size(self, stack_size: usize) -> Self
pub fn stack_size(self, stack_size: usize) -> Self
Sourcepub fn keep_alive(self, keep_alive: Duration) -> Self
pub fn keep_alive(self, keep_alive: Duration) -> Self
Sourcepub fn allow_core_thread_timeout(self, allow: bool) -> Self
pub fn allow_core_thread_timeout(self, allow: bool) -> Self
Sourcepub fn prestart_core_threads(self) -> Self
pub fn prestart_core_threads(self) -> Self
Starts all core workers during Self::build.
Without this option, workers are created lazily as tasks are submitted,
matching the default JDK ThreadPoolExecutor behavior.
§Returns
This builder for fluent configuration.
Sourcepub fn build(self) -> Result<ThreadPool, ThreadPoolBuildError>
pub fn build(self) -> Result<ThreadPool, ThreadPoolBuildError>
Builds the configured thread pool.
§Returns
Ok(ThreadPool) if the configuration is valid and all requested
prestarted workers are spawned successfully.
§Errors
Returns ThreadPoolBuildError if the configuration is invalid or a
prestarted worker thread cannot be spawned.
Trait Implementations§
Source§impl Clone for ThreadPoolBuilder
impl Clone for ThreadPoolBuilder
Source§fn clone(&self) -> ThreadPoolBuilder
fn clone(&self) -> ThreadPoolBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more