4 releases
0.1.3 | Mar 7, 2024 |
---|---|
0.1.2 | Apr 9, 2023 |
0.1.1 | Mar 10, 2023 |
0.1.0 | Mar 8, 2023 |
#13 in #task-queue
29KB
547 lines
JTP
An implementation of a thread pool that is similar to ThreadPoolExecutor
in java.
Usage
Install this library using cargo
,
cargo add jtp
Or add this to your Cargo.toml
:
[dependencies]
jtp = "0.1.3"
And use this library:
// Creates a thread pool.
let thread_pool = ThreadPoolBuilder::default()
.core_pool_size(6) // Sets the number of core threads.
.max_pool_size(10) // Sets the maximum number of threads.
.channel_capacity(100) // Sets the capacity of the task queue.
.rejected_handler(RejectedTaskHandler::Abort)
.build();
thread_pool.execute(|| println!("Hello World"));
thread_pool.wait();
License
Apache License, Version 2.0, LICENSE-APACHE
lib.rs
:
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();
thread_pool.execute(|| println!("Hello World")).unwrap();
// Close the thread pool and wait for all worker threads to end.
thread_pool.wait();
Dependencies
~425KB