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 pool_size(self, pool_size: usize) -> ThreadPoolBuilder
pub fn pool_size(self, pool_size: usize) -> ThreadPoolBuilder
Sourcepub fn core_pool_size(self, core_pool_size: usize) -> ThreadPoolBuilder
pub fn core_pool_size(self, core_pool_size: usize) -> ThreadPoolBuilder
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) -> ThreadPoolBuilder
pub fn maximum_pool_size(self, maximum_pool_size: usize) -> ThreadPoolBuilder
Sourcepub fn queue_capacity(self, capacity: usize) -> ThreadPoolBuilder
pub fn queue_capacity(self, capacity: usize) -> ThreadPoolBuilder
Sourcepub fn unbounded_queue(self) -> ThreadPoolBuilder
pub fn unbounded_queue(self) -> ThreadPoolBuilder
Sourcepub fn thread_name_prefix(self, prefix: &str) -> ThreadPoolBuilder
pub fn thread_name_prefix(self, prefix: &str) -> ThreadPoolBuilder
Sourcepub fn stack_size(self, stack_size: usize) -> ThreadPoolBuilder
pub fn stack_size(self, stack_size: usize) -> ThreadPoolBuilder
Sourcepub fn keep_alive(self, keep_alive: Duration) -> ThreadPoolBuilder
pub fn keep_alive(self, keep_alive: Duration) -> ThreadPoolBuilder
Sourcepub fn allow_core_thread_timeout(self, allow: bool) -> ThreadPoolBuilder
pub fn allow_core_thread_timeout(self, allow: bool) -> ThreadPoolBuilder
Sourcepub fn prestart_core_threads(self) -> ThreadPoolBuilder
pub fn prestart_core_threads(self) -> ThreadPoolBuilder
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 before_worker_start<F>(self, hook: F) -> ThreadPoolBuilder
pub fn before_worker_start<F>(self, hook: F) -> ThreadPoolBuilder
Sourcepub fn after_worker_stop<F>(self, hook: F) -> ThreadPoolBuilder
pub fn after_worker_stop<F>(self, hook: F) -> ThreadPoolBuilder
Sourcepub fn before_task<F>(self, hook: F) -> ThreadPoolBuilder
pub fn before_task<F>(self, hook: F) -> ThreadPoolBuilder
Sourcepub fn after_task<F>(self, hook: F) -> ThreadPoolBuilder
pub fn after_task<F>(self, hook: F) -> ThreadPoolBuilder
Sourcepub fn build(self) -> Result<ThreadPool, ExecutorServiceBuilderError>
pub fn build(self) -> Result<ThreadPool, ExecutorServiceBuilderError>
Builds the configured thread pool.
§Returns
Ok(ThreadPool) if the configuration is valid and all requested
prestarted workers are spawned successfully.
§Errors
Returns ExecutorServiceBuilderError 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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ThreadPoolBuilder
impl Debug for ThreadPoolBuilder
Source§impl Default for ThreadPoolBuilder
impl Default for ThreadPoolBuilder
Source§fn default() -> ThreadPoolBuilder
fn default() -> ThreadPoolBuilder
Creates a builder with CPU parallelism defaults.
§Returns
A builder configured with CPU parallelism for both core and maximum sizes, an unbounded queue, and the default keep-alive timeout.
Auto Trait Implementations§
impl Freeze for ThreadPoolBuilder
impl !RefUnwindSafe for ThreadPoolBuilder
impl Send for ThreadPoolBuilder
impl Sync for ThreadPoolBuilder
impl Unpin for ThreadPoolBuilder
impl UnsafeUnpin for ThreadPoolBuilder
impl !UnwindSafe for ThreadPoolBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more