jimu-decompiled/sources/com/liulishuo/filedownloader/util/FileDownloadExecutors.java
2025-05-13 19:24:51 +02:00

53 lines
1.9 KiB
Java

package com.liulishuo.filedownloader.util;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes.dex */
public class FileDownloadExecutors {
static class FileDownloadThreadFactory implements ThreadFactory {
private final String a;
private final AtomicInteger c = new AtomicInteger(1);
private final ThreadGroup b = Thread.currentThread().getThreadGroup();
static {
new AtomicInteger(1);
}
FileDownloadThreadFactory(String str) {
this.a = FileDownloadUtils.k(str);
}
@Override // java.util.concurrent.ThreadFactory
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(this.b, runnable, this.a + this.c.getAndIncrement(), 0L);
if (thread.isDaemon()) {
thread.setDaemon(false);
}
if (thread.getPriority() != 5) {
thread.setPriority(5);
}
return thread;
}
}
public static ThreadPoolExecutor a(String str) {
return new ThreadPoolExecutor(0, Integer.MAX_VALUE, 15L, TimeUnit.SECONDS, new SynchronousQueue(), new FileDownloadThreadFactory(str));
}
public static ThreadPoolExecutor a(int i, String str) {
return a(i, new LinkedBlockingQueue(), str);
}
public static ThreadPoolExecutor a(int i, LinkedBlockingQueue<Runnable> linkedBlockingQueue, String str) {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(i, i, 15L, TimeUnit.SECONDS, linkedBlockingQueue, new FileDownloadThreadFactory(str));
threadPoolExecutor.allowCoreThreadTimeOut(true);
return threadPoolExecutor;
}
}