question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to manage IOException caused by Deadline.throwIfReached

See original GitHub issue

Hi!

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:closed
  • Created 9 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
cesardscommented, May 7, 2014

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:

If you call cancel(true), an interrupt will be sent to the background thread, which may help interruptible tasks. Otherwise, you should simply make sure to check isCancelled() regularly in your doInBackground() method. You can see examples of this at code.google.com/p/shelves.

I stopped using AsyncTask long time ago :S . Am I suppose InterruptedIOException is thrown correctly?

0reactions
cesardscommented, May 8, 2014

Thank you guys!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found