0

My app is required to scan a subnet for responding devices (and check port 80/8080 for a specific service). I was using an executorservice/threadpool to complete the scan task - which took approx 30 seconds to complete.

I rewrote the above process to use an asynctask - the process now takes much longer (many minutes).

I've gone back to the original executorservice and wrapped this whole process in an asynctask as a compromise (so it doesn't block the UI and completes quickly) but doubt this is best practice. It also creates issues with progress updates, cancelling etc.

Is it best that I go with the slower process, that provides UI updates/cancellable facility or (as the whole process only takes 30s) - go with the faster, executorservice?

Thanks.

tw332
  • 47
  • 3
  • 11
  • All you need to do is adjust the priority, see [here](http://stackoverflow.com/a/14217816/1856738). – class stacker Apr 13 '13 at 13:27
  • Also bear in mind that `AsyncTask`, when used with `execute()`, is serialized on Android 3.2+ devices if your `android:targetSdkVersion` is set to 13 or higher. You have to specifically use `executeOnExecutor()` and opt into the multiple-thread `AsyncTask` thread pool. – CommonsWare Apr 13 '13 at 13:29
  • It turns out my issue wasn't with the priority of the asynctask, more that it was running sequentially. I'm now experimenting with executeOnExecutor and handling queuing tasks (as I have 255 to run). I've tried using executeOnExecutor on my Executor but it is still partially blocking the UI. – tw332 Apr 14 '13 at 19:52

0 Answers0