Please enable JavaScript.
Coggle requires JavaScript to display documents.
8.1 Implicit Couplings Between Tasks and Execution Policies - Coggle…
8.1 Implicit Couplings Between Tasks and Execution Policies
Executor Framework Flexibility
Not all tasks compatible with all execution policies
Types of tasks needing specific policies:
Dependent Tasks
Tasks depend on timing/results/side effects of others
Constraints on execution policy to avoid liveness problems
Tasks Exploiting Thread Confinement
Single-threaded executors guarantee non-concurrent execution
Relaxed thread safety assumptions
Risk if moved to a multi-threaded executor
Response-Time-Sensitive Tasks
GUI tasks sensitive to delays
Risk with long-running tasks or small thread pools
Tasks Using ThreadLocal
Each thread has a private variable
Risks with thread reuse and lifetime mismatches
ThreadLocal should not communicate between tasks
Best Practices for Thread Pools
Work best with homogeneous, independent tasks
Risks:
Mixing short- and long-running tasks can clog pool
Task dependencies can cause deadlock
Specific Problems
Thread Starvation Deadlock
Dependent tasks deadlock if queued behind one another
Happens in single-threaded and poorly sized pools
Important to document pool sizing/configuration constraints
Implicit resource limits (e.g., database connection pools)
Long-Running Tasks
Degrades responsiveness
All threads can be occupied by long tasks
Techniques to mitigate:
Use timed waits (e.g., Thread.join, BlockingQueue.put)
Timeout tasks and requeue or fail them
Indicates pool might be too small
Documentation Importance
Document task-specific requirements for execution policies
Prevent future misconfigurations that could cause safety or liveness problems