How to manage IOException caused by Deadline.throwIfReached
See original GitHub issueHi!
I would like to know if it’s possible to use the next function
public boolean reached() {
return System.nanoTime() - deadlineNanos >= 0; // Subtract to avoid overflow!
}
I’m using Picasso inside of AsyncTask for getting a bitmap and set it to imageview manually. Currently, working with the common API is not an option for me, because I can’t cancel requests (I’m working with vertical and horizontal viewpager and they can hold up to 11 images at the same time). I use asynctask and its cancellation, but I get an InterruptedIOException
@Override protected Bitmap doInBackground(String... params) {
RequestCreator requestCreator = Picasso.with(getActivity()).load(params[0]);
try {
if (!isCancelled()) {
Bitmap source = requestCreator.get();
if (source != null) {
Bitmap result = ImageUtil.createScaledBitmap(source, (int) destW, (int) destH, ImageUtil.ScaleLogic.FIT);
if (result != source) {
source.recycle();
}
return result;
}
}
} catch (OutOfMemoryError e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
InterruptedIOException and NetworkIOException
My app crashes randomly and I do not know what cause the error. I'm using RxJava2 to get the file list. Here is...
Read more >java.io.InterruptedIOException.getMessage java code examples
deadlineNanoTime (System.nanoTime()); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) ...
Read more >Timeout (Okio 1.17.4 API) - javadoc.io
Returns true if a deadline is enabled. void, throwIfReached(). Throws an InterruptedIOException if the deadline has been reached or if the current thread ......
Read more >Android IO 框架Okio 的实现原理,如何检测超时?
@Throws(IOException::class) open fun throwIfReached() { if ... 抛出超时异常 throw InterruptedIOException("deadline reached") } } 复制代码.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

As @MarkMurphy says:
Call cancel() on the AsyncTask. Whether or not this will actually cancel anything is dependent a bit upon what you are doing. To quote Romain Guy:
I stopped using AsyncTask long time ago :S . Am I suppose InterruptedIOException is thrown correctly?
Thank you guys!