Expand description
Thread Pool
A thread pool allows you to execute asyncronous tasks without creating new threads for each one. It improves the performance and the resource utilization by limiting the number of threads.
Build a thread pool
You can use the ThreadPoolBuilder to build a thread pool with
the custom configuration.
Examples
use jtp::ThreadPoolBuilder;
let mut thread_pool = ThreadPoolBuilder::default()
.core_pool_size(5)
.max_pool_size(10)
.channel_capacity(100)
.build()
.unwrap();
thread_pool.execute(|| println!("Hello World")).unwrap();
// Close the thread pool and wait for all worker threads to end.
thread_pool.wait();Structs
- An error returned from the
ThreadPoolBuilder::build. - A
ThreadPoolconsists of a collection of reusable threads and a bounded channel that is used to transfer and hold submitted tasks. - A builder of the
ThreadPool, which can be used to configure the properties of a new thread pool.
Enums
- If a task is rejected, the task will be handled by this.
- An error returned from the
ThreadPool::execute.
Type Definitions
- A function that used to create a custom thread.