package 㴹.K.Ԕ.ⁱ;

import io.reactivex.internal.schedulers.RxThreadFactory;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import ඓ.ⁱ.K.ඓ.C1252;

/* renamed from: 㴹.K.Ԕ.ⁱ.㴹  reason: contains not printable characters */
/* compiled from: SchedulerPoolFactory */
public final class C2477 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public static final Map<ScheduledThreadPoolExecutor, Object> f8456 = new ConcurrentHashMap();

    /* renamed from: ῲ  reason: contains not printable characters */
    public static final AtomicReference<ScheduledExecutorService> f8457 = new AtomicReference<>();

    /* renamed from: K  reason: contains not printable characters */
    public static final int f8458;

    /* renamed from: 㴹.K.Ԕ.ⁱ.㴹$K  reason: contains not printable characters */
    /* compiled from: SchedulerPoolFactory */
    public static final class RunnableC2478 implements Runnable {
        public void run() {
            try {
                Iterator it2 = new ArrayList(C2477.f8456.keySet()).iterator();
                while (it2.hasNext()) {
                    ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = (ScheduledThreadPoolExecutor) it2.next();
                    if (scheduledThreadPoolExecutor.isShutdown()) {
                        C2477.f8456.remove(scheduledThreadPoolExecutor);
                    } else {
                        scheduledThreadPoolExecutor.purge();
                    }
                }
            } catch (Throwable th) {
                C1252.m3349(th);
            }
        }
    }

    static {
        Properties properties = System.getProperties();
        f8458 = (!properties.containsKey("rx2.purge-enabled") || !Boolean.getBoolean("rx2.purge-enabled") || !properties.containsKey("rx2.purge-period-seconds")) ? 1 : Integer.getInteger("rx2.purge-period-seconds", 1).intValue();
        while (true) {
            ScheduledExecutorService scheduledExecutorService = f8457.get();
            if (scheduledExecutorService == null || scheduledExecutorService.isShutdown()) {
                ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1, new RxThreadFactory("RxSchedulerPurge"));
                if (f8457.compareAndSet(scheduledExecutorService, newScheduledThreadPool)) {
                    RunnableC2478 k = new RunnableC2478();
                    long j = (long) f8458;
                    newScheduledThreadPool.scheduleAtFixedRate(k, j, j, TimeUnit.SECONDS);
                    return;
                }
                newScheduledThreadPool.shutdownNow();
            } else {
                return;
            }
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public static ScheduledExecutorService m6517(ThreadFactory threadFactory) {
        ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1, threadFactory);
        if (newScheduledThreadPool instanceof ScheduledThreadPoolExecutor) {
            f8456.put((ScheduledThreadPoolExecutor) newScheduledThreadPool, newScheduledThreadPool);
        }
        return newScheduledThreadPool;
    }
}
