Initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.alibaba.android.arouter.thread;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class CancelableCountDownLatch extends CountDownLatch {
|
||||
public CancelableCountDownLatch(int i) {
|
||||
super(i);
|
||||
}
|
||||
|
||||
public void a() {
|
||||
while (getCount() > 0) {
|
||||
countDown();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
package com.alibaba.android.arouter.thread;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.alibaba.android.arouter.utils.TextUtils;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class DefaultPoolExecutor extends ThreadPoolExecutor {
|
||||
private static final int a = Runtime.getRuntime().availableProcessors();
|
||||
private static final int b = a + 1;
|
||||
private static final int c = b;
|
||||
private static DefaultPoolExecutor d;
|
||||
|
||||
private DefaultPoolExecutor(int i, int i2, long j, TimeUnit timeUnit, BlockingQueue<Runnable> blockingQueue, ThreadFactory threadFactory) {
|
||||
super(i, i2, j, timeUnit, blockingQueue, threadFactory, new RejectedExecutionHandler() { // from class: com.alibaba.android.arouter.thread.DefaultPoolExecutor.1
|
||||
@Override // java.util.concurrent.RejectedExecutionHandler
|
||||
public void rejectedExecution(Runnable runnable, ThreadPoolExecutor threadPoolExecutor) {
|
||||
ARouter.c.b("ARouter::", "Task rejected, too many task!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static DefaultPoolExecutor a() {
|
||||
if (d == null) {
|
||||
synchronized (DefaultPoolExecutor.class) {
|
||||
if (d == null) {
|
||||
d = new DefaultPoolExecutor(b, c, 30L, TimeUnit.SECONDS, new ArrayBlockingQueue(64), new DefaultThreadFactory());
|
||||
}
|
||||
}
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ThreadPoolExecutor
|
||||
protected void afterExecute(Runnable runnable, Throwable th) {
|
||||
super.afterExecute(runnable, th);
|
||||
if (th == null && (runnable instanceof Future)) {
|
||||
try {
|
||||
((Future) runnable).get();
|
||||
} catch (InterruptedException unused) {
|
||||
Thread.currentThread().interrupt();
|
||||
} catch (CancellationException e) {
|
||||
th = e;
|
||||
} catch (ExecutionException e2) {
|
||||
th = e2.getCause();
|
||||
}
|
||||
}
|
||||
if (th != null) {
|
||||
ARouter.c.c("ARouter::", "Running task appeared exception! Thread [" + Thread.currentThread().getName() + "], because [" + th.getMessage() + "]\n" + TextUtils.a(th.getStackTrace()));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
package com.alibaba.android.arouter.thread;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import java.lang.Thread;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class DefaultThreadFactory implements ThreadFactory {
|
||||
private static final AtomicInteger d = new AtomicInteger(1);
|
||||
private final AtomicInteger a = new AtomicInteger(1);
|
||||
private final ThreadGroup b;
|
||||
private final String c;
|
||||
|
||||
public DefaultThreadFactory() {
|
||||
SecurityManager securityManager = System.getSecurityManager();
|
||||
this.b = securityManager != null ? securityManager.getThreadGroup() : Thread.currentThread().getThreadGroup();
|
||||
this.c = "ARouter task pool No." + d.getAndIncrement() + ", thread No.";
|
||||
}
|
||||
|
||||
@Override // java.util.concurrent.ThreadFactory
|
||||
public Thread newThread(Runnable runnable) {
|
||||
String str = this.c + this.a.getAndIncrement();
|
||||
ARouter.c.d("ARouter::", "Thread production, name is [" + str + "]");
|
||||
Thread thread = new Thread(this.b, runnable, str, 0L);
|
||||
if (thread.isDaemon()) {
|
||||
thread.setDaemon(false);
|
||||
}
|
||||
if (thread.getPriority() != 5) {
|
||||
thread.setPriority(5);
|
||||
}
|
||||
thread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(this) { // from class: com.alibaba.android.arouter.thread.DefaultThreadFactory.1
|
||||
@Override // java.lang.Thread.UncaughtExceptionHandler
|
||||
public void uncaughtException(Thread thread2, Throwable th) {
|
||||
ARouter.c.d("ARouter::", "Running task appeared exception! Thread [" + thread2.getName() + "], because [" + th.getMessage() + "]");
|
||||
}
|
||||
});
|
||||
return thread;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user