Skip to content

Commit b48c4c8

Browse files
author
krishna
committed
increase the corePoolSize and MaxPoolSize of AsyncTaskExecutor
1 parent ce8554b commit b48c4c8

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

fileloader/src/main/java/com/krishna/fileloader/FileLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static MultiFileDownloader multiFileDownload(Context context) {
7979

8080
public FileResponse loadFile() throws Exception {
8181
validateAllParameters();
82-
DownloadResponse response = getFileLoaderAsyncTask().execute().get();
82+
DownloadResponse response = getFileLoaderAsyncTask().executeOnExecutor(Utils.getThreadPoolExecutor()).get();
8383
if (response.getDownloadedFile() != null) {
8484
return createFileResponse(response.getDownloadedFile());
8585
} else {
@@ -102,7 +102,7 @@ public void loadFileAsync() {
102102
synchronized (REQUEST_QUEUE_LOCK) {
103103
fileLoadRequestSet.add(fileLoadRequest);
104104
}
105-
getFileLoaderAsyncTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
105+
getFileLoaderAsyncTask().executeOnExecutor(Utils.getThreadPoolExecutor());
106106
}
107107
}
108108

fileloader/src/main/java/com/krishna/fileloader/utility/Utils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
import java.io.FileInputStream;
77
import java.io.IOException;
88
import java.io.ObjectInputStream;
9+
import java.util.concurrent.BlockingQueue;
10+
import java.util.concurrent.LinkedBlockingQueue;
11+
import java.util.concurrent.ThreadPoolExecutor;
12+
import java.util.concurrent.TimeUnit;
913

1014
/**
1115
* Created by krishna on 15/10/17.
@@ -35,4 +39,12 @@ private static Object deserializeObject(File file, Class clazz) throws IOExcepti
3539
in.close();
3640
return object;
3741
}
42+
43+
public static ThreadPoolExecutor getThreadPoolExecutor() {
44+
int mCorePoolSize = 60;
45+
int mMaximumPoolSize = 80;
46+
int mKeepAliveTime = 30;
47+
BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(mMaximumPoolSize);
48+
return new ThreadPoolExecutor(mCorePoolSize, mMaximumPoolSize, mKeepAliveTime, TimeUnit.SECONDS, workQueue);
49+
}
3850
}

0 commit comments

Comments
 (0)