Last active
January 2, 2018 17:36
-
-
Save Ansh1234/7c67802abd5f77dae0f95ba2d13a9353 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PicassoExecutorService extends ThreadPoolExecutor { | |
private static final int DEFAULT_THREAD_COUNT = 3; | |
PicassoExecutorService() { | |
super(DEFAULT_THREAD_COUNT, DEFAULT_THREAD_COUNT, 0, TimeUnit.MILLISECONDS, | |
new PriorityBlockingQueue<Runnable>(), new Utils.PicassoThreadFactory()); | |
} | |
void adjustThreadCount(NetworkInfo info) { | |
if (info == null || !info.isConnectedOrConnecting()) { | |
setThreadCount(DEFAULT_THREAD_COUNT); | |
return; | |
} | |
switch (info.getType()) { | |
case ConnectivityManager.TYPE_WIFI: | |
// Some more code. | |
setThreadCount(4); | |
break; | |
case ConnectivityManager.TYPE_MOBILE: | |
// Some more if/else conditioning | |
setThreadCount(2); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment