pub struct FixedThreadPool { /* private fields */ }Expand description
Fixed-size thread pool implementing ExecutorService.
FixedThreadPool prestarts a fixed number of worker threads and does not
support runtime pool-size changes. Use crate::ThreadPool when dynamic
core/maximum sizes or keep-alive policies are required.
Implementations§
Source§impl FixedThreadPool
impl FixedThreadPool
Sourcepub fn new(pool_size: usize) -> Result<Self, ExecutorServiceBuilderError>
pub fn new(pool_size: usize) -> Result<Self, ExecutorServiceBuilderError>
Creates a fixed thread pool with pool_size prestarted workers.
§Parameters
pool_size- Number of worker threads.
§Returns
A fixed thread pool.
§Errors
Returns ExecutorServiceBuilderError if the worker count is zero or a worker
cannot be spawned.
Sourcepub fn builder() -> FixedThreadPoolBuilder
pub fn builder() -> FixedThreadPoolBuilder
Sourcepub fn queued_count(&self) -> usize
pub fn queued_count(&self) -> usize
Sourcepub fn running_count(&self) -> usize
pub fn running_count(&self) -> usize
Sourcepub fn live_worker_count(&self) -> usize
pub fn live_worker_count(&self) -> usize
Sourcepub fn stats(&self) -> ThreadPoolStats
pub fn stats(&self) -> ThreadPoolStats
Returns a point-in-time stats snapshot.
§Returns
Snapshot containing queue, worker, and lifecycle counters.
Trait Implementations§
Source§impl Default for FixedThreadPool
impl Default for FixedThreadPool
Source§impl Drop for FixedThreadPool
impl Drop for FixedThreadPool
Source§impl ExecutorService for FixedThreadPool
impl ExecutorService for FixedThreadPool
Source§fn submit<T, E>(&self, task: T) -> Result<(), SubmissionError>
fn submit<T, E>(&self, task: T) -> Result<(), SubmissionError>
Accepts a runnable and queues it for fixed pool workers.
Source§fn submit_callable<C, R, E>(
&self,
task: C,
) -> Result<Self::ResultHandle<R, E>, SubmissionError>
fn submit_callable<C, R, E>( &self, task: C, ) -> Result<Self::ResultHandle<R, E>, SubmissionError>
Accepts a callable and queues it for fixed pool workers.
§Parameters
task- Callable to execute on a fixed pool worker.
§Returns
A TaskHandle for the accepted task.
§Errors
Returns SubmissionError::Shutdown after shutdown or
SubmissionError::Saturated when a bounded queue is full.
Source§fn submit_tracked_callable<C, R, E>(
&self,
task: C,
) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
fn submit_tracked_callable<C, R, E>( &self, task: C, ) -> Result<Self::TrackedHandle<R, E>, SubmissionError>
Accepts a callable and queues it with a tracked handle.
§Parameters
task- Callable to execute on a fixed pool worker.
§Returns
A TrackedTask that reports task status and can observe completion,
failure, or queued cancellation.
§Errors
Returns SubmissionError::Shutdown after shutdown or
SubmissionError::Saturated when a bounded queue is full.
Source§fn stop(&self) -> StopReport
fn stop(&self) -> StopReport
Source§fn lifecycle(&self) -> ExecutorServiceLifecycle
fn lifecycle(&self) -> ExecutorServiceLifecycle
Returns the current lifecycle state.
Source§fn is_not_running(&self) -> bool
fn is_not_running(&self) -> bool
Returns whether shutdown has been requested.
§Returns
true when this pool no longer accepts new work.
Source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
Returns whether this pool is fully terminated.
§Returns
true after shutdown and after all workers have exited.
Source§fn wait_termination(&self)
fn wait_termination(&self)
Blocks until this fixed pool has terminated.