AsyncTask : java.util.concurrent.RejectedExecutionException

by arnouf » Wed, 07 Apr 2010 21:41:45 GMT

Sponsored Links

I'm trying to launch a lot of remote connection retrieve picture on a
server. To do this, I use AsyncTask.

This pics are displayed in a listview using adapter. If I implement
this in my adapter, images are retrieved but the display is bad
(problem with index or something like that).
If I try to retrieve image when I build my object list (contained in
my listview), I get the exception
04-07 13:35:57.744: ERROR/AndroidRuntime(4132): Caused by:
04-07 13:35:57.744: ERROR/AndroidRuntime(4132):     at
04-07 13:35:57.744: ERROR/AndroidRuntime(4132):     at
04-07 13:35:57.744: ERROR/AndroidRuntime(4132):     at
04-07 13:35:57.744: ERROR/AndroidRuntime(4132):     at

What is this exception ? Why I can launch multiple asynctask in my
listview (giving to me a bad result) and not in a simple object
without having this issue ?

Thanks for your explanations.


AsyncTask : java.util.concurrent.RejectedExecutionException

by Mark Murphy » Wed, 07 Apr 2010 21:57:57 GMT

 > What is this exception ?

The second link in a Google search for RejectedExecutionException turns up: 

Your problem is probably the second on that list -- you have tried to
start too many AsyncTasks. AsyncTask uses a limited-length BlockingQueue
for jobs waiting for a thread in the thread pool to free up, and it will
throw that exception when you exceed the available number of slots in the

Mark Murphy (a Commons Guy) 
Android App Developer Books: 


Sponsored Links

AsyncTask : java.util.concurrent.RejectedExecutionException

by arnouf » Wed, 07 Apr 2010 22:35:23 GMT

 Ok thanks Mark.
When you have a lot of Image to load this is a big limitation.
Strangely, we don't have this situation If I call the same number of
element inside a listview...But another issue appears : images are not
placed on good lines :(


AsyncTask : java.util.concurrent.RejectedExecutionException

by Mark Murphy » Wed, 07 Apr 2010 22:38:14 GMT

 > When you have a lot of Image to load this is a big limitation.

You can:

-- Grab the source code to AsyncTask, clone it into your own package, and
modify the LinkedBlockingQueue. I did this with my AsyncTaskEx class.

-- Skip AsyncTask and roll your own thread pool.

Mark Murphy (a Commons Guy) 
Android App Developer Books: 


AsyncTask : java.util.concurrent.RejectedExecutionException

by arnouf » Wed, 07 Apr 2010 23:14:42 GMT

 I'm not sure that it will resolve my first problem related to the
image loaded from remote and display in my listview
I can use Asynctask in my adapter to load each image. But when I do a
bog scroll, displayed image are not to the good place (ex. : the image
number 4 is displayed at the line 15 ...). It's trying to tesolve this
first issue, that I meet the exception. But this issue is maybe due to
the Async pool too.

I come you back later.



AsyncTask : java.util.concurrent.RejectedExecutionException

by Greg Giacovelli » Sat, 10 Apr 2010 01:36:56 GMT

 Hi arnouf,
I don't mean to butt in but I suspect this is a similar problem to
something I saw before.

In your ViewAdapter, I am assuming you are creating or using a View
which is or contains an ImageView which you are trying to load the
image contents for remotely. If you are always creating the view in
your adapter, then it simplifies the process a lot but at a
performance tradeoff since you won't get the View recycling that the
ListView does for you. If you create only when the view passed into
your adapter is null, and use the passed in View other times then you
gain some performance, however now you have to sync the ImageViews to
what is being displayed on the screen or else like you said, you may
get images rendered in the incorrect cells of the list.

So there are 2 problems,

#1 For the AsyncTask, you can still use the AsyncTask, but stagger
their execution (try using a handler on the UI thread to spawn the
AsyncTask after a delay, via postDelay).

#2 The Image Syncing problem, when you get the information back you
should make sure the view that the task is loading the image for is
not "dirty." By dirty I mean that the ListView is still displaying
that cell and it is the correct cell. It may have been recycled and
passed back to your adapter as the user scrolled and you will end up
out of sync. I have been storing the image url in the tag of the image
view and on a successful image load comparing the tag with the source
of the image bitmap to make sure the view still is "fresh." If you
cache the image somewhere (in memory or storage) you can then retrieve
it faster later and just fill the image view next time that cell needs
to be rendered.

Not sure if this is the exact problem you describe but I don't see any
harm in giving some advice. Hope it helps.



Other Threads

1. Desire Froyo Official Claimed by Adam_g of open desire

langsung aj nih :p


"Indonesian Android Community [id-android]" 

2. Problem with Multicast sockets

Hello folks,

I'm running some code on the nexus one - and I am having a very
strange issue. The "server" sends UDP packets out on the multicast
socket that the phone is joined to. The phone receives and sends stuff
to the multicast group fine, but it appears that the phone chokes when
it receives a large number of packets at one time.

For example, the server will occasionally send out 80 or so 512 byte
packets in one go around. The phone starts receiving the packets, but
then at the 31st packet (~16KB of data) the receive hangs (indicating
that there is nothing on the socket anymore.) I've done wireshark
testing and stuff so I know for sure that the packets are not being
lost. Even if some are being lost, it is very strange that EVERY test
produces the same result --- a large amount of data gets jammed onto
the socket at one time, but the socket only allows me to
socket.receive() for 16KB worth of data.

I have tried socket.setReceiveBufferSize() with a variety of values
(up to 1MB) -- but that doesn't seem to work. Interestingly, a call to
getReceiveBufferSize() tells me that the socket should hold roughly
100KB worth of data.

If I tell the server to slow down its send method (which I cannot
deploy, I can only do that for testing purposes) - everything works
fine, presumably because the packets aren't jammed onto the phone's
socket all at one time (ie. I tell the server to wait 1/2 a second
between packets.)

Has anyone else experienced this - if so - how did you get around it?
I *cannot* switch the application to TCP.


- Dan


3. Load images from a device and store in the app memory

4. Selected listview item with a shadow effect at boundaries

5. button text in new line

6. Animasi Booting id-android - EVO+ Desir

7. Blacklisted Apps