[concurrency-interest] Callable inside a Runnable and RejectedExecutionException

Tim Peierls tim at peierls.net
Wed Dec 13 15:45:51 EST 2006


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20061213/365c1375/attachment.html 


More information about the Concurrency-interest mailing list