← 返回 sofi 的题目列表Multi-Threaded Task Executor
类型:qbank
Implement an extensible task executor around semaphore-like thread acquisition and task subclasses with different execution behaviors.
Requirements
Implement a TaskExecutor class that follows a semaphore-style API.
Required methods include initialization(), execution(), and acquire().
The executor receives multiple Task subclasses through a common interface.
Each task subclass has different behavior.
Example behaviors include MultiplyTask, which multiplies input, consumes x threads, and does not return on finish; and DivideTask, which divides input, consumes y threads, and returns when finished.
The design should emphasize extensibility and maintainability, not only getting one hard-coded task case to pass.
Notes
The interviewer was testing OOD principles as much as concurrency mechanics.
Prepare to explain where semaphore acquisition belongs, how task behavior is polymorphic, and how new task types would be added without rewriting the executor.