jimu-decompiled/sources/com/tencent/open/utils/h.java
2025-05-13 19:24:51 +02:00

96 lines
2.8 KiB
Java

package com.tencent.open.utils;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import java.lang.reflect.Field;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/* compiled from: ProGuard */
/* loaded from: classes.dex */
public final class h {
private static Handler c;
private static HandlerThread d;
private static Object b = new Object();
public static final Executor a = c();
/* compiled from: ProGuard */
private static class a implements Executor {
final Queue<Runnable> a;
Runnable b;
private a() {
this.a = new LinkedList();
}
protected synchronized void a() {
Runnable poll = this.a.poll();
this.b = poll;
if (poll != null) {
h.a.execute(this.b);
}
}
@Override // java.util.concurrent.Executor
public synchronized void execute(final Runnable runnable) {
this.a.offer(new Runnable() { // from class: com.tencent.open.utils.h.a.1
@Override // java.lang.Runnable
public void run() {
try {
runnable.run();
} finally {
a.this.a();
}
}
});
if (this.b == null) {
a();
}
}
}
public static Handler a() {
if (c == null) {
synchronized (h.class) {
d = new HandlerThread("SDK_SUB");
d.start();
c = new Handler(d.getLooper());
}
}
return c;
}
public static Executor b() {
return new a();
}
private static Executor c() {
Executor threadPoolExecutor;
if (Build.VERSION.SDK_INT >= 11) {
threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue());
} else {
try {
Field declaredField = AsyncTask.class.getDeclaredField("sExecutor");
declaredField.setAccessible(true);
threadPoolExecutor = (Executor) declaredField.get(null);
} catch (Exception unused) {
threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.SECONDS, new LinkedBlockingQueue());
}
}
if (threadPoolExecutor instanceof ThreadPoolExecutor) {
((ThreadPoolExecutor) threadPoolExecutor).setCorePoolSize(3);
}
return threadPoolExecutor;
}
public static void a(Runnable runnable) {
a().post(runnable);
}
}