package com.mbridge.msdk.foundation.same.e;

import com.mbridge.msdk.MBridgeConstans;
import com.mbridge.msdk.foundation.tools.af;
import com.mbridge.msdk.foundation.tools.ah;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/* compiled from: CommonTaskLoaderThreadPool.java */
/* loaded from: classes5.dex */
public final class c {

    /* renamed from: a  reason: collision with root package name */
    private static volatile ThreadPoolExecutor f3625a;

    private static int a(int i, String str) {
        try {
            int a2 = ah.a().a(str, i);
            return a2 <= 0 ? i : a2;
        } catch (Exception e) {
            if (MBridgeConstans.DEBUG) {
                af.b("CommonTaskLoaderThreadPool", e.getMessage());
                return i;
            }
            return i;
        }
    }

    public static ThreadPoolExecutor a() {
        if (f3625a == null) {
            int a2 = a(10, "c_t_l_t_p_c");
            int a3 = a(50, "c_t_l_t_p_m");
            int a4 = a(5, "c_t_l_t_p_t");
            int i = a3 < a2 ? a2 : a3;
            try {
                if (MBridgeConstans.DEBUG) {
                    af.a("CommonTaskLoaderThreadPool", "create ThreadPoolExecutor for core " + a2 + " max " + i + " timeout " + a4);
                }
                long j = a4;
                if (j <= 0) {
                    j = 1;
                }
                f3625a = new ThreadPoolExecutor(a2, i, j, TimeUnit.SECONDS, new LinkedBlockingDeque(), new ThreadFactory() { // from class: com.mbridge.msdk.foundation.same.e.c.1
                    @Override // java.util.concurrent.ThreadFactory
                    public final Thread newThread(Runnable runnable) {
                        Thread thread = new Thread(runnable);
                        thread.setName("mb-task-loader-thread");
                        return thread;
                    }
                }, new ThreadPoolExecutor.DiscardPolicy());
                f3625a.allowCoreThreadTimeOut(true);
            } catch (Exception e) {
                if (MBridgeConstans.DEBUG) {
                    af.b("CommonTaskLoaderThreadPool", "create ThreadPoolExecutor failed ", e);
                }
            }
        }
        if (f3625a == null) {
            int availableProcessors = (Runtime.getRuntime().availableProcessors() * 2) + 1;
            f3625a = new ThreadPoolExecutor(availableProcessors, availableProcessors, 10L, TimeUnit.MILLISECONDS, new LinkedBlockingDeque(), new ThreadFactory() { // from class: com.mbridge.msdk.foundation.same.e.c.1
                @Override // java.util.concurrent.ThreadFactory
                public final Thread newThread(Runnable runnable) {
                    Thread thread = new Thread(runnable);
                    thread.setName("mb-task-loader-thread");
                    return thread;
                }
            }, new ThreadPoolExecutor.DiscardPolicy());
            f3625a.allowCoreThreadTimeOut(true);
        }
        return f3625a;
    }
}
