import: reduce number of threads a little, and code cleanup
This commit is contained in:
@@ -82,6 +82,8 @@ import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
|||||||
*/
|
*/
|
||||||
public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
||||||
|
|
||||||
|
public static final int MAX_THREADS = 10;
|
||||||
|
|
||||||
public ImportOperation(Context context, ProviderHelper providerHelper, Progressable
|
public ImportOperation(Context context, ProviderHelper providerHelper, Progressable
|
||||||
progressable) {
|
progressable) {
|
||||||
super(context, providerHelper, progressable);
|
super(context, providerHelper, progressable);
|
||||||
@@ -412,18 +414,15 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private ImportKeyResult multiThreadedKeyImport(Iterator<ParcelableKeyRing> keyListIterator,
|
private ImportKeyResult multiThreadedKeyImport(@NonNull Iterator<ParcelableKeyRing> keyListIterator,
|
||||||
int totKeys, final String keyServer,
|
int totKeys, final String keyServer,
|
||||||
final Proxy proxy) {
|
final Proxy proxy) {
|
||||||
Log.d(Constants.TAG, "Multi-threaded key import starting");
|
Log.d(Constants.TAG, "Multi-threaded key import starting");
|
||||||
if (keyListIterator != null) {
|
|
||||||
KeyImportAccumulator accumulator = new KeyImportAccumulator(totKeys, mProgressable);
|
KeyImportAccumulator accumulator = new KeyImportAccumulator(totKeys, mProgressable);
|
||||||
|
|
||||||
final ProgressScaler ignoreProgressable = new ProgressScaler();
|
final ProgressScaler ignoreProgressable = new ProgressScaler();
|
||||||
|
|
||||||
final int maxThreads = 200;
|
ExecutorService importExecutor = new ThreadPoolExecutor(0, MAX_THREADS, 30L, TimeUnit.SECONDS,
|
||||||
ExecutorService importExecutor = new ThreadPoolExecutor(0, maxThreads,
|
|
||||||
30L, TimeUnit.SECONDS,
|
|
||||||
new SynchronousQueue<Runnable>());
|
new SynchronousQueue<Runnable>());
|
||||||
|
|
||||||
ExecutorCompletionService<ImportKeyResult> importCompletionService =
|
ExecutorCompletionService<ImportKeyResult> importCompletionService =
|
||||||
@@ -465,8 +464,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return accumulator.getConsolidatedResult();
|
return accumulator.getConsolidatedResult();
|
||||||
}
|
|
||||||
return new ImportKeyResult(ImportKeyResult.RESULT_FAIL_NOTHING, new OperationLog());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -500,7 +498,7 @@ public class ImportOperation extends BaseOperation<ImportKeyringParcel> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void accumulateKeyImport(ImportKeyResult result) {
|
public void accumulateKeyImport(ImportKeyResult result) {
|
||||||
mImportedKeys++;
|
mImportedKeys++;
|
||||||
|
|
||||||
if (mProgressable != null) {
|
if (mProgressable != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user