class DefaultProtectedStrategy implements ProviderProtectedStrategy, StatisticCallback {
    protected ConcurrentMap<String, AtomicInteger> requestCounters = new ConcurrentHashMap<>();
    protected ConcurrentMap<String, AtomicInteger> rejectCounters = new ConcurrentHashMap<>();
    protected AtomicInteger totalCounter = new AtomicInteger(0);
    protected AtomicInteger rejectCounter = new AtomicInteger(0);
    protected AtomicInteger methodCounter = new AtomicInteger(1);

    public DefaultProtectedStrategy() {
        StatsUtil.registryStatisticCallback(this);
    }

    @Override
    public void setMethodCounter(AtomicInteger methodCounter) {
        this.methodCounter = methodCounter;
    }

    @Override
    public Response call(Request request, Provider<?> provider) {<FILL_FUNCTION_BODY>}

    private Response reject(String method, int requestCounter, int totalCounter, int maxThread, Request request) {
        String message = "ThreadProtectedRequestRouter reject request: request_method=" + method + " request_counter=" + requestCounter
                + " total_counter=" + totalCounter + " max_thread=" + maxThread;
        MotanServiceException exception = new MotanServiceException(message, MotanErrorMsgConstant.SERVICE_REJECT, false);
        DefaultResponse response = MotanFrameworkUtil.buildErrorResponse(request, exception);
        LoggerUtil.error(exception.getMessage());
        incrCounter(method, rejectCounters);
        rejectCounter.incrementAndGet();
        return response;
    }

    private int incrCounter(String requestKey, ConcurrentMap<String, AtomicInteger> counters) {
        AtomicInteger counter = counters.get(requestKey);
        if (counter == null) {
            counter = new AtomicInteger(0);
            counters.putIfAbsent(requestKey, counter);
            counter = counters.get(requestKey);
        }
        return counter.incrementAndGet();
    }

    private int decrCounter(String requestKey, ConcurrentMap<String, AtomicInteger> counters) {
        AtomicInteger counter = counters.get(requestKey);
        if (counter == null) {
            return 0;
        }
        return counter.decrementAndGet();
    }

    private int incrTotalCounter() {
        return totalCounter.incrementAndGet();
    }

    private int decrTotalCounter() {
        return totalCounter.decrementAndGet();
    }

    public boolean isAllowRequest(int requestCounter, int totalCounter, int maxThread) {

        // 方法总数为1或该方法第一次请求, 直接return true
        if (methodCounter.get() == 1 || requestCounter == 1) {
            return true;
        }

        // 不简单判断 requestCount > (maxThread / 2) ，因为假如有2或者3个method对外提供，
        // 但是只有一个接口很大调用量，而其他接口很空闲，那么这个时候允许单个method的极限到 maxThread * 3 / 4
        if (requestCounter > (maxThread / 2) && totalCounter > (maxThread * 3 / 4)) {
            return false;
        }

        // 如果总体线程数超过 maxThread * 3 / 4个，并且对外的method比较多，那么意味着这个时候整体压力比较大，
        // 那么这个时候如果单method超过 maxThread * 1 / 4，那么reject
        return !(methodCounter.get() >= 4 && totalCounter > (maxThread * 3 / 4) && requestCounter > (maxThread / 4));
    }

    @Override
    public String statisticCallback() {
        int count = rejectCounter.getAndSet(0);
        if (count > 0) {
            StringBuilder builder = new StringBuilder();
            builder.append("type:").append("motan").append(" ")
                    .append("name:").append("reject_request").append(" ")
                    .append("total_count:").append(totalCounter.get()).append(" ")
                    .append("reject_count:").append(count).append(" ");
            for (Map.Entry<String, AtomicInteger> entry : rejectCounters.entrySet()) {
                String key = entry.getKey();
                int cnt = entry.getValue().getAndSet(0);
                builder.append(key).append("_reject:").append(cnt).append(" ");
            }
            return builder.toString();
        } else {
            return null;
        }
    }

    @Override
    public Map<String, Object> getRuntimeInfo() {
        Map<String, Object> infos = new HashMap<>();
        infos.put("totalCount", totalCounter.get());
        infos.put("rejectCount", rejectCounter.get());
        Map<String, Object> methodRequestCounts = new HashMap<>();
        for (Map.Entry<String, AtomicInteger> entry : requestCounters.entrySet()) {
            methodRequestCounts.put(entry.getKey(), entry.getValue().get());
        }
        infos.put("requestCounts", methodRequestCounts);
        Map<String, Object> methodRejectCounts = new HashMap<>();
        for (Map.Entry<String, AtomicInteger> entry : rejectCounters.entrySet()) {
            methodRejectCounts.put(entry.getKey(), entry.getValue().get());
        }
        infos.put("rejectCounts", methodRejectCounts);
        return infos;
    }
}

        // 支持的最大worker thread数
        int maxThread = provider.getUrl().getIntParameter(URLParamType.maxWorkerThread.getName(), URLParamType.maxWorkerThread.getIntValue());

        String requestKey = MotanFrameworkUtil.getFullMethodString(request);

        try {
            int requestCounter = incrCounter(requestKey, requestCounters);
            int totalCounter = incrTotalCounter();
            if (isAllowRequest(requestCounter, totalCounter, maxThread)) {
                return provider.call(request);
            } else {
                // reject request
                return reject(request.getInterfaceName() + "." + request.getMethodName(), requestCounter, totalCounter, maxThread, request);
            }
        } finally {
            decrTotalCounter();
            decrCounter(requestKey, requestCounters);
        }
    
<no_super_class>