package io.reactivex.internal.schedulers; 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; /* loaded from: classes2.dex */ public final class SchedulerPoolFactory { public static final boolean a; public static final int b; static final AtomicReference c = new AtomicReference<>(); static final Map d = new ConcurrentHashMap(); static final class PurgeProperties { boolean a; int b; PurgeProperties() { } void a(Properties properties) { if (properties.containsKey("rx2.purge-enabled")) { this.a = Boolean.parseBoolean(properties.getProperty("rx2.purge-enabled")); } else { this.a = true; } if (!this.a || !properties.containsKey("rx2.purge-period-seconds")) { this.b = 1; return; } try { this.b = Integer.parseInt(properties.getProperty("rx2.purge-period-seconds")); } catch (NumberFormatException unused) { this.b = 1; } } } static final class ScheduledTask implements Runnable { ScheduledTask() { } @Override // java.lang.Runnable public void run() { Iterator it = new ArrayList(SchedulerPoolFactory.d.keySet()).iterator(); while (it.hasNext()) { ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = (ScheduledThreadPoolExecutor) it.next(); if (scheduledThreadPoolExecutor.isShutdown()) { SchedulerPoolFactory.d.remove(scheduledThreadPoolExecutor); } else { scheduledThreadPoolExecutor.purge(); } } } } static { Properties properties = System.getProperties(); PurgeProperties purgeProperties = new PurgeProperties(); purgeProperties.a(properties); a = purgeProperties.a; b = purgeProperties.b; a(); } public static void a() { a(a); } static void a(boolean z) { if (!z) { return; } while (true) { ScheduledExecutorService scheduledExecutorService = c.get(); if (scheduledExecutorService != null) { return; } ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1, new RxThreadFactory("RxSchedulerPurge")); if (c.compareAndSet(scheduledExecutorService, newScheduledThreadPool)) { ScheduledTask scheduledTask = new ScheduledTask(); int i = b; newScheduledThreadPool.scheduleAtFixedRate(scheduledTask, i, i, TimeUnit.SECONDS); return; } newScheduledThreadPool.shutdownNow(); } } public static ScheduledExecutorService a(ThreadFactory threadFactory) { ScheduledExecutorService newScheduledThreadPool = Executors.newScheduledThreadPool(1, threadFactory); a(a, newScheduledThreadPool); return newScheduledThreadPool; } static void a(boolean z, ScheduledExecutorService scheduledExecutorService) { if (z && (scheduledExecutorService instanceof ScheduledThreadPoolExecutor)) { d.put((ScheduledThreadPoolExecutor) scheduledExecutorService, scheduledExecutorService); } } }