critical section
The part of a program that reads and writes shared state and must therefore be run by only one thread at a time.
In more detail
Keep critical sections as small as possible so other threads are not kept waiting. Holding a lock while calling a slow service is a common cause of poor throughput.
Related terms
- synchronized — The Java keyword that lets only one thread at a time run a block of code guarded by the same lock object.
- race condition — A bug whose outcome depends on the timing of two things happening at once.
Taught in
- Concurrency Basics: Threads And Runnable — Modern Java: Virtual Threads & High-Throughput Services