AsyncTask : java.util.concurrent.RejectedExecutionException

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


Sponsored Links
 Hello,

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:
java.util.concurrent.RejectedExecutionException
04-07 13:35:57.744: ERROR/AndroidRuntime(4132):     at
java.util.concurrent.ThreadPoolExecutor
$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1876)
04-07 13:35:57.744: ERROR/AndroidRuntime(4132):     at
java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:
774)
04-07 13:35:57.744: ERROR/AndroidRuntime(4132):     at
java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:
1295)
04-07 13:35:57.744: ERROR/AndroidRuntime(4132):     at
android.os.AsyncTask.execute(AsyncTask.java:394)

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:

 http://pveentjer.wordpress.com/2008/02/06/are-you-dealing-with-the-rejectedexecutionexception/ 

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
queue.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Android App Developer Books:  http://commonsware.com/books.html 


--


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)
 http://commonsware.com 
Android App Developer Books:  http://commonsware.com/books.html 


--



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.

Thanks




--



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.

-Greg





--



Other Threads

1. Standard Android Music Player

Is there any way to pass a file or a playlist to a standard Android
Music Player? I guess almost all applications, for instance, i Music
do it.

-- 

2. Help Needed With Some Layout - UI Problems

Hi,
I'd like to create an UI existing out of the following elements :

<LinearLayout>
    <TableLayout>
        <TableRow>
           <ImageButton>
           <TextView>
        </TableRow>
   </TableLayout>
   <ScrollView>
      <TableLayout>
         <TableRow>
            <ImageButton>
            <ImageButton>
         </TableRow>
          <TableRow>
            <ImageButton>
            <ImageButton>
         </TableRow>
          <TableRow>
            <ImageButton>
            <ImageButton>
         </TableRow>
      </TableLayout>
    </ScrollView>

So in short :
A vertical LinearLayout, which contains first a TableLayout with just
one TableRow, and afterwards a Scrollable Table...

If I try it like above I actually will only see the first TableLayout,
the ScrollView (with it's tabel and tablerows) won't show at all...
I read that within a ScrollView there should be a LinearLayout and in
there the TableLayout...
So I did that and it works but ONLY if I completely remove the first
TableLayout, which I actually want to keep..

So is this some kind of know bug, or how could I possibly solve this ?
Is it possible for a ScrollView to co-exist with another TableLayout
(on the same XML "level") ? Or can it onky exits if it's the only
child of the base-layout ?

-- 

3. How to send motion Event down to another activity

4. Paging om Tio Ping

5. F-sale:Nexus One bnib,OOT palm pre

6. About boot.img

7. Feeding Media player from non-rtsp/non-file source