ants icon indicating copy to clipboard operation
ants copied to clipboard

提个建议: 增加拒绝策略

Open Yballul opened this issue 2 years ago • 1 comments

java的 threadPoolExecutor里面有拒绝策略。其中callerRunsPolicy能够让 被池子拒绝的任务交给调用者自己执行 一些比较重要的任务是不希望被池子拒绝后丢弃的 希望ants pool也可以加一个这样的东西

Yballul avatar Aug 04 '22 08:08 Yballul

ThreadPoolExecutor 的拒绝策略也只是在 pool 满了之后的一些动作,用 ants 的话你可以设置 NonBlocking,这样 pool 满了之后你再调用 Submit() 就直接返回错误而非阻塞住:https://pkg.go.dev/github.com/panjf2000/ants/v2#WithNonblocking,也可以设置最大允许在等待的调用方:https://pkg.go.dev/github.com/panjf2000/ants/v2#WithMaxBlockingTasks。

panjf2000 avatar Aug 06 '22 12:08 panjf2000