[concurrency-interest] Callable inside a Runnable and RejectedExecutionException

Tim Peierls tim at peierls.net
Wed Dec 13 17:28:22 EST 2006


By "having a Callable in a Runnable" you mean "submitting a Callable task to
an ExecutorService within a Runnable task being executed by that same
service", right? There's nothing wrong with that in principle.

You might have inter-task dependencies that are exacerbated by the timed
get. Could it be that your ExecutorService is filling up very quickly with
tasks waiting for other tasks that can't run? If you use a separate
ExecutorService for the listTasks, does that improve matters?

Sorry that I don't have time to look into this more carefully...

--tim


On 12/13/06, robert lazarski <robertlazarski at gmail.com> wrote:
>
> This is just proof of concept code, but I'll take the suggestion.
> Here's the stack trace:
>
> [java] Caused by: java.util.concurrent.RejectedExecutionException
>      [java]     at
> java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(
> ThreadPoolExecutor.java:1477)
>      [java]     at
> java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java
> :384)
>      [java]     at
> java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java
> :856)
>      [java]     at
> java.util.concurrent.AbstractExecutorService.submit(
> AbstractExecutorService.java:45)
>      [java]     at org.DNS$2.run(DNS.java:147)
>
> Where DNS.java:147 is exec.submit(listTask) . I thought it might be
> something about having Callable in a Runnable, but maybe not?
>
> Robert
>
>
> On 12/13/06, Tim Peierls <tim at peierls.net> wrote:
> > What does it throw?
> >
> > I haven't looked carefully at this code, but consider getting rid of
> "catch
> > (Exception e) {...}" clauses in favor of more specific exception
> handling.
> >
> > --tim
> >
> >
> >  On 12/13/06, robert lazarski <robertlazarski at gmail.com> wrote:
> > >
> > > Hi all, getting closer on my DNS problem. One of the things I'm
> > > noticing is that on some Context.list() calls are taking too much time
> > > to timeout. Unfortunately putting in a new dep such as dnsjava in this
> > > project is a hard sell. Anyways What I'd like to do is limit the time
> > > this  list() call can take via a Future. Is it illegal to have a
> > > Callable inside Runnable? The code below throws on
> > > exec.submit(listTask). Thanks for any help.
> > >
> > >   private static void parallelRecursiveDNS(final ExecutorService exec,
> > > final DirContext ictx,
> > >           final NamingEnumeration hostEnumeration, final
> > > Collection<String> domainsVisitedQueue,
> > >           final Collection<String> results)
> > >       throws Exception {
> > >
> > >       taskCount.incrementAndGet();
> > >
> > >       while (hostEnumeration.hasMore()) {
> > >
> > >           exec.execute(new Runnable() {
> > >               public void run() {
> > >                   long runStart = System.currentTimeMillis ();
> > >                   try {
> > >                       String host = null;
> > >                       host = ((NameClassPair) hostEnumeration.next())
> > >                               .getNameInNamespace();
> > >                       if ( results.contains(host)) {
> > >                           return;
> > >                       }
> > >                       results.add(host);
> > >                       out.println("Found host: " + host);
> > >                       Attributes aDNS =
> > ictx.getAttributes(host,
> > >                                   new String[] { "NS" });
> > >                       NamingEnumeration allDNS =
> > aDNS.getAll();
> > >                       while (allDNS.hasMore()) {
> > >                            out.println("Entering allDNS: ");
> > >                           Attribute attr = (Attribute)
> > allDNS.next();
> > >                           NamingEnumeration values =
> > attr.getAll();
> > >                           final String dns = values.next().toString();
> > >                           if (domainsVisitedQueue.contains(dns)) {
> > >                               continue;
> > >                           }
> > >                           domainsVisitedQueue.add (dns);
> > >
> > >                           NamingEnumeration
> > newEnumeration;
> > >                           boolean gotList = false;
> > >                           try {
> > >                               Callable
> > <NamingEnumeration> listTask =
> > >                                   new
> > Callable<NamingEnumeration>() {
> > >                                       public
> > NamingEnumeration call() {
> > >                                           try {
> > >                                               return
> > ictx.list(dns);
> > >                                           } catch
> > (Exception ex) {
> > >
> > ex.printStackTrace();
> > >                                           }
> > >                                           return null;
> > >                                       }
> > >                                   };
> > >                               Future <NamingEnumeration>
> > future =
> > > exec.submit(listTask);
> > >                               newEnumeration =
> > future.get(10L,
> > > TimeUnit.SECONDS);
> > >                               if (hostEnumeration !=
> > null) {
> > >                                   gotList = true;
> > >                               }
> > >                           } catch (Exception ex) {
> > >                               ex.printStackTrace();
> > >                               throw new Exception(ex);
> > >                           }
> > >                           if (!gotList) {
> > >                               continue;
> > >                           }
> > >                           parallelRecursiveDNS(exec,
> > ictx,
> > > newEnumeration, domainsVisitedQueue, results);
> > >                       }
> > >                   } catch (Exception ex) {
> > >                        ex.printStackTrace();
> > >                   } finally {
> > >                       long runEnd = System.currentTimeMillis();
> > >                       out.println("runnable execution time was "
> > >                         + (runEnd - runStart) / 1000 + " seconds ");
> > >                       if (taskCount.decrementAndGet() == 0) {
> > >                       }
> > >                   }
> > >
> > >               }
> > >           });
> > >       }
> > >   }
> > > _______________________________________________
> > > Concurrency-interest mailing list
> > > Concurrency-interest at altair.cs.oswego.edu
> > >
> > http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
> > >
> >
> >
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20061213/5e359d6d/attachment-0001.html 


More information about the Concurrency-interest mailing list