I need to download a number of bitmaps from server into android. I want to use an AsyncTask executed using .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
. But my executor is getting overwhelmed. So I figure, if I put a delay, that should help. So my question: how do I put a delay on an executor? I am thinking of using handler.postDelay
but that only accepts runnables. Is there a way to get it to work with an executor?
A good solution might be to run 20 calls at a time and then wait 100 milliseconds to run the next 20. Does anyone know a way to do that on android?
@pete
I am using one thread per call. I wasn't sure if multiple calls in one thread would cause a problem.
@Override
protected Bitmap doInBackground(Void... params) {
try {
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
return BitmapFactory.decodeStream(is);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}