bookkeeper
bookkeeper copied to clipboard
fix: throw reject when SingleThreadExecutor drainTo in progress and queue is empty
Fix #4465
Motivaction
In SingleThreadExecutor, the runner drains the full queue into the localTasks, when the localTasks has not been run, the queue is really full(the queue is empty in the memory) at this point.
When calling the execute() method, which shouldn't add the runnable to the queue, which would double the actual number of runable, increasing memory usage and potential OOM issues.
Changes
Add a variable to record the runnable count:
- When we add the runnable to the queue, the value is increased by 1.
- When we run the runnable, the value is reduced by 1.