Hi, I have an http client based on multi-threaded model of apache http components in my App. And I want to achieve spontaneous cancellation of http get requests from my Android app.
A new executor thread is started for each http request and the Thread and the HttpGet is saved in a thread safe queue. When abort is requested (on pressing back on the progress dialog and when starting a new activity) - another thread is started which goes through the queue of Threads and HttpGet and attempts to terminate them (code below). While the HttpGet gets aborted successfully, the Threads go into 'native' state. They only time out giving SocketTimeoutException after a default interval. The threads end up this way on most cancellations. Is this something to be expected or I am hitting a bug? The issue is that And as soon as 2 threads enter this state, all further executor threads go into wait. Only when either of the 2 blocked threads time out, other executors get a chance (this seems to be the default behavior of http). I have have tried many different thing but I am unable to budge the 'stuck' threads. I think the problem can be easily overcome by increasing the total no of threads and threads per host -- but I am not sure if this will be a correct thing to do (because the socket resources will stay occupied till timeout and there is nothing theoretically that can stop a user to do infinite cancellations)? Even if this is -- for Android, what should be the number? Now I am also doubting if my abort strategy is flawed. Can anyone please commentor let me know of a fool-proof abort strategy? - - - Run method of the abort thread is like: public void run() { while (!stopQueue.isEmpty()) { final List<Object> stopRequest = stopQueue.remove(); HttpGet abortRequest = (HttpGet) stopRequest.get(0); Thread abortThread = (Thread) stopRequest.get(1); // first abort the request if (abortRequest != null && !abortRequest.isAborted()) { abortRequest.abort(); Log.d("Aborting", abortRequest.getURI().toString()); } // if the thread is still stuck -- interrupt it if (abortThread != null && abortThread.isAlive()) { abortThread.interrupt(); Log.d("Interrupting", abortThread.getName()); } } } Thanks Anurag -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en