Prevent NPE

pull/210/head
M66B 2 years ago
parent 466a04f764
commit f84c332c9e

@ -251,7 +251,7 @@ public class Helper {
static ExecutorService sSerialTaskExecutor = null; static ExecutorService sSerialTaskExecutor = null;
static int sOperationIndex = 0; static int sOperationIndex = 0;
static ExecutorService[] sOperationExecutor = new ExecutorService[OPERATION_WORKERS]; static final ExecutorService[] sOperationExecutor = new ExecutorService[OPERATION_WORKERS];
static ExecutorService getSerialExecutor() { static ExecutorService getSerialExecutor() {
if (sSerialExecutor == null) if (sSerialExecutor == null)
@ -272,12 +272,14 @@ public class Helper {
} }
static ExecutorService getOperationExecutor() { static ExecutorService getOperationExecutor() {
synchronized (sOperationExecutor) {
if (sOperationExecutor[sOperationIndex] == null) if (sOperationExecutor[sOperationIndex] == null)
sOperationExecutor[sOperationIndex] = getBackgroundExecutor(1, "operation"); sOperationExecutor[sOperationIndex] = getBackgroundExecutor(1, "operation");
ExecutorService result = sOperationExecutor[sOperationIndex]; ExecutorService result = sOperationExecutor[sOperationIndex];
sOperationIndex = (sOperationIndex + 1) % sOperationExecutor.length; sOperationIndex = (sOperationIndex + 1) % sOperationExecutor.length;
return result; return result;
} }
}
private static ExecutorService getBackgroundExecutor(int threads, final String name) { private static ExecutorService getBackgroundExecutor(int threads, final String name) {
ThreadFactory factory = new ThreadFactory() { ThreadFactory factory = new ThreadFactory() {

Loading…
Cancel
Save