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 super::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, ThreadPoolBuildError>
pub fn new(pool_size: usize) -> Result<Self, ThreadPoolBuildError>
Creates a fixed thread pool with pool_size prestarted workers.
§Parameters
pool_size- Number of worker threads.
§Returns
A fixed thread pool.
§Errors
Returns ThreadPoolBuildError 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 Drop for FixedThreadPool
impl Drop for FixedThreadPool
Source§impl ExecutorService for FixedThreadPool
impl ExecutorService for FixedThreadPool
Source§fn submit_callable<C, R, E>(
&self,
task: C,
) -> Result<Self::Handle<R, E>, RejectedExecution>
fn submit_callable<C, R, E>( &self, task: C, ) -> Result<Self::Handle<R, E>, RejectedExecution>
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 RejectedExecution::Shutdown after shutdown or
RejectedExecution::Saturated when a bounded queue is full.
Source§fn shutdown_now(&self) -> ShutdownReport
fn shutdown_now(&self) -> ShutdownReport
Source§fn is_shutdown(&self) -> bool
fn is_shutdown(&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 await_termination(&self) -> Self::Termination<'_>
fn await_termination(&self) -> Self::Termination<'_>
Waits until this fixed pool has terminated.
§Returns
A future that blocks the polling thread until termination.