- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
125 lines
3.9 KiB
Java
125 lines
3.9 KiB
Java
package com.ea.nimble.tracking;
|
|
|
|
import com.ea.nimble.Log;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.Future;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledFuture;
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/* loaded from: classes2.dex */
|
|
class NimbleTrackingThreadManager {
|
|
private static NimbleTrackingThreadManager s_instance;
|
|
private static int s_instanceRefs;
|
|
private final ScheduledExecutorService m_executor = new ScheduledThreadPoolExecutor(1) { // from class: com.ea.nimble.tracking.NimbleTrackingThreadManager.1
|
|
@Override // java.util.concurrent.ThreadPoolExecutor
|
|
public void afterExecute(Runnable runnable, Throwable th) {
|
|
Log.Helper.LOGFUNC(this);
|
|
super.afterExecute(runnable, th);
|
|
if (th == null && (runnable instanceof Future)) {
|
|
Future future = (Future) runnable;
|
|
if (!future.isCancelled()) {
|
|
try {
|
|
future.get();
|
|
} catch (InterruptedException unused) {
|
|
Thread.currentThread().interrupt();
|
|
} catch (ExecutionException e) {
|
|
th = e.getCause();
|
|
}
|
|
}
|
|
}
|
|
if (th != null) {
|
|
if (th instanceof Error) {
|
|
throw ((Error) th);
|
|
}
|
|
if (th instanceof RuntimeException) {
|
|
throw ((RuntimeException) th);
|
|
}
|
|
Log.Helper.LOGES("TrackingThreadManager", "Checked exception thrown from Tracking thread:", new Object[0]);
|
|
th.printStackTrace();
|
|
}
|
|
}
|
|
};
|
|
|
|
public static abstract class BlockingRunner {
|
|
private boolean m_done = false;
|
|
|
|
public abstract void run();
|
|
|
|
public BlockingRunner() {
|
|
Log.Helper.LOGPUBLICFUNC(this);
|
|
run();
|
|
waitUntilDone();
|
|
}
|
|
|
|
public void setDone() {
|
|
Log.Helper.LOGFUNC(this);
|
|
synchronized (this) {
|
|
this.m_done = true;
|
|
notifyAll();
|
|
}
|
|
}
|
|
|
|
private void waitUntilDone() {
|
|
Log.Helper.LOGFUNC(this);
|
|
if (this.m_done) {
|
|
return;
|
|
}
|
|
synchronized (this) {
|
|
while (!this.m_done) {
|
|
try {
|
|
wait();
|
|
} catch (InterruptedException unused) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static NimbleTrackingThreadManager acquireInstance() {
|
|
if (s_instance == null) {
|
|
s_instance = new NimbleTrackingThreadManager();
|
|
}
|
|
s_instanceRefs++;
|
|
return s_instance;
|
|
}
|
|
|
|
public static void releaseInstance() {
|
|
int i = s_instanceRefs - 1;
|
|
s_instanceRefs = i;
|
|
if (i == 0) {
|
|
s_instance.shutdown();
|
|
s_instance = null;
|
|
}
|
|
}
|
|
|
|
public ScheduledFuture<?> createTimer(double d, Runnable runnable) {
|
|
return this.m_executor.schedule(runnable, (long) (d * 1000.0d), TimeUnit.MILLISECONDS);
|
|
}
|
|
|
|
public void runInWorkerThread(Runnable runnable) {
|
|
runInWorkerThread(false, runnable);
|
|
}
|
|
|
|
public void runInWorkerThread(boolean z, Runnable runnable) {
|
|
if (z) {
|
|
try {
|
|
this.m_executor.submit(runnable).get();
|
|
return;
|
|
} catch (InterruptedException unused) {
|
|
Thread.currentThread().interrupt();
|
|
return;
|
|
} catch (ExecutionException unused2) {
|
|
return;
|
|
}
|
|
}
|
|
this.m_executor.execute(runnable);
|
|
}
|
|
|
|
private void shutdown() {
|
|
Log.Helper.LOGFUNC(this);
|
|
this.m_executor.shutdown();
|
|
}
|
|
}
|