Skip to content

Instantly share code, notes, and snippets.

@Ansh1234
Last active January 2, 2018 17:36
Show Gist options
  • Save Ansh1234/7c67802abd5f77dae0f95ba2d13a9353 to your computer and use it in GitHub Desktop.
Save Ansh1234/7c67802abd5f77dae0f95ba2d13a9353 to your computer and use it in GitHub Desktop.
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