A simple HTTP server that handles multiple requests concurrently using a thread pool instead of spawning a new thread per request.
A ThreadPool holds:
- Workers — a fixed number of threads (e.g., 3)
- Sender — sends jobs into a channel
- Receiver — (in each worker) receives jobs from the channel
When you call pool.execute(closure), the closure is boxed and sent through an mpsc channel. A waiting worker receives it, runs it, then goes back to sleep at recv() waiting for the next job.
cargo runThen visit:
localhost:7878/— returnshello.htmllocalhost:7878/sleep— simulates a slow request (thread sleeps for 5s) to verify multi-threaded handlinglocalhost:7878/<anything else>— returns a 404 page