public static CWorkItem <T> QueueWorkItem <T>(this ThreadIsolationCommand <T> command, Func <T> func, EventHandler <StatusChangeEventArgs> onStatusChange = null) { CThreadPool commandPool = GetCommandPool(command); if (commandPool.NowWaitingWorkCount >= ((commandPool.MaxConcurrentCount * command.ConfigSet.MaxAsyncCommandExceedPercentage) / 100)) { throw new HystrixException(FailureTypeEnum.ThreadIsolationRejected, command.GetType(), command.Key, "already exceed the max workitem, can't add any more."); } return(commandPool.QueueWorkItem <T>(func, onStatusChange)); }
public static CWorkItem <T> QueueWorkItem <T>(this ThreadIsolationCommand <T> command, Func <T> func, EventHandler <StatusChangeEventArgs> onStatusChange = null) { var pool = GetCommandPool(command); //if (pool.NowRunningWorkCount >= pool.MaxConcurrentCount) //{ // command.Metrics.MarkExecutionEvent(CommandExecutionEventEnum.ThreadMaxActive); //} //when asyn command's count exceed thread pool's volume, only allow some percentage (reference pool volume) task queue. if (pool.NowWaitingWorkCount >= pool.MaxConcurrentCount * command.ConfigSet.MaxAsyncCommandExceedPercentage / 100) { throw new HystrixException(FailureTypeEnum.ThreadIsolationRejected, command.GetType(), command.Key, "already exceed the max workitem, can't add any more."); //new ExecutionRejectedException("already exceed the max workitem, can't add any more."); } //command.Metrics.MarkExecutionEvent(CommandExecutionEventEnum.ThreadExecution); return(pool.QueueWorkItem(func, onStatusChange)); }