14.ThreadPool
Java · 4 notes
- 6.14 14.ThreadPoolhistorical
1. What it is. Java's thread-pool framework separates task submission from task execution. 1.1. Why thread pools are needed: reuse threads, because creating/destroying threads is expensive and too many threads cause excessive CPU context switching. 1.2. Use cases: individual tasks should not run too long, and there are many tasks.
- 6.28 Executorshistorical
1. Usage 2. newCachedThreadPool 3. newScheduledThreadPool 4. newFixedThreadPool 5. newSingleThreadExecutor
- 6.36 RejectedExecutionHandlerhistorical
1. What is RejectedExecutionHandler? When corePoolSize is full, blockingQueue is full, and maxPoolSize is also full, how should a new task be handled? This is determined by RejectedExecutionHandler. 2. Types: CallerRunsPolicy, AbortPolicy, DiscardPolicy, DiscardOldestPolicy.
- Estimating Thread Pool Sizehistorical
1. Estimate the number of threads 1.1. Throughput = concurrency / response time 1.2. TPS estimation 1.3. I/O-intensive or CPU-intensive 1.4. Dark Magic 2. References