Documentation ¶
Index ¶
- Constants
- Variables
- func GoRoutinePool(allowCoreThreadTimeOut bool, corePoolSize, maxPoolSize int64, ...) *goRoutinePool
- func NewChanTaskQueue(maxQueueSize int64) *chanTaskQueue
- func NewGoRoutinePool(corePoolSize, maxPoolSize int64, keepAliveTime time.Duration, ...) *goRoutinePool
- type AbortPolicy
- type CallerRunsPolicy
- type DiscardOldestPolicy
- type DiscardPolicy
- type GoRoutineWork
- type IGoRoutinePool
- type IGoRoutinePoolQueue
- type IGoRoutinePoolRejectedPolicy
- type NewGoRoutineRunsPolicy
- type Runnable
Constants ¶
Variables ¶
View Source
var AbortPolicyError = errors.New("abort reject execution")
View Source
var CallerRunsPolicyError = errors.New("caller runs policy reject execution")
View Source
var DiscardOldestPolicyError = errors.New("discard oldest policy reject execution")
View Source
var DiscardPolicyPolicyError = errors.New("discard policy reject execution")
View Source
var ExecuteAddWorkerError = errors.New("execute add worker error")
View Source
var ExecuteRunnableError = errors.New("execute runnable error")
View Source
var Nil = errors.New("anything is nil")
View Source
var PoolStatusError = errors.New("pool status error")
View Source
var PoolStopStatusError = errors.New("pool stop status error")
View Source
var PoolTerminateStatusError = errors.New("pool terminate status error")
View Source
var QueueEmpty = errors.New("Queue empty")
View Source
var QueueFull = errors.New("Queue full")
View Source
var RunnableNil = errors.New("runnable is nil")
Functions ¶
func GoRoutinePool ¶
func GoRoutinePool(allowCoreThreadTimeOut bool, corePoolSize, maxPoolSize int64, keepAliveTime time.Duration, queue IGoRoutinePoolQueue, policy IGoRoutinePoolRejectedPolicy) *goRoutinePool
func NewChanTaskQueue ¶
func NewChanTaskQueue(maxQueueSize int64) *chanTaskQueue
func NewGoRoutinePool ¶
func NewGoRoutinePool(corePoolSize, maxPoolSize int64, keepAliveTime time.Duration, queue IGoRoutinePoolQueue, rejectedPolicy IGoRoutinePoolRejectedPolicy) *goRoutinePool
Types ¶
type AbortPolicy ¶
type AbortPolicy struct { }
func (*AbortPolicy) RejectedExecution ¶
func (p *AbortPolicy) RejectedExecution(Runnable, IGoRoutinePool) (bool, error)
type CallerRunsPolicy ¶
type CallerRunsPolicy struct { }
func (*CallerRunsPolicy) RejectedExecution ¶
func (p *CallerRunsPolicy) RejectedExecution(r Runnable, pool IGoRoutinePool) (bool, error)
type DiscardOldestPolicy ¶
type DiscardOldestPolicy struct { }
DiscardOldestPolicy:把队列最老的丢了,再执行当前的
func (*DiscardOldestPolicy) RejectedExecution ¶
func (p *DiscardOldestPolicy) RejectedExecution(r Runnable, pool IGoRoutinePool) (bool, error)
type DiscardPolicy ¶
type DiscardPolicy struct { }
DiscardPolicy:任务直接丢弃
func (*DiscardPolicy) RejectedExecution ¶
func (p *DiscardPolicy) RejectedExecution(r Runnable, pool IGoRoutinePool) (bool, error)
type GoRoutineWork ¶
type GoRoutineWork struct {
// contains filtered or unexported fields
}
GoRoutineWork 执行者
func NewWork ¶
func NewWork(task Runnable, name string, core bool, pool IGoRoutinePool) *GoRoutineWork
type IGoRoutinePool ¶
type IGoRoutinePool interface { Execute(Runnable) (bool, error) IsShutdown() bool TryTerminate() (bool, error) AwaitTermination(unit time.Duration) (bool, error) GetTask(allowCoreThreadTimeOut bool) (Runnable, error) //从同步队列取任务 AddTask(Runnable) (bool, error) //增加任务 Queue() IGoRoutinePoolQueue RemoveWorker(string, bool) (bool, error) //取出任务队列 AddCompletedTasks(int64) bool // 增加已经完成的任务数 }
ITaskPool 线程池:核心数量、最大数量、业余队列存活时间&时间单元、同步队列&队列满后执行策略
type IGoRoutinePoolQueue ¶
type IGoRoutinePoolQueue interface { IsEmpty() bool Size() int64 // 直接存任务,可能会失败 Add(r Runnable) (bool, error) // 直接取任务,可能为空 Take() (Runnable, error) // 尝试一定时间内放任务 Offer(r Runnable, unit time.Duration) (bool, error) // 尝试一定时间取任务 Poll(unit time.Duration) (Runnable, error) }
ITaskPoolQueue 线程安全 Put Pool
type IGoRoutinePoolRejectedPolicy ¶
type IGoRoutinePoolRejectedPolicy interface {
RejectedExecution(Runnable, IGoRoutinePool) (bool, error)
}
协程池满了,队列满了,要怎么拒绝任务呢?
type NewGoRoutineRunsPolicy ¶
type NewGoRoutineRunsPolicy struct { }
func (*NewGoRoutineRunsPolicy) RejectedExecution ¶
func (p *NewGoRoutineRunsPolicy) RejectedExecution(r Runnable, pool IGoRoutinePool) (bool, error)
Click to show internal directories.
Click to hide internal directories.