[concurrency-interest] Migrating DNS problem to j.u.c

robert lazarski robertlazarski at gmail.com
Mon Dec 11 14:34:46 EST 2006

Hi all,

I've been tasked with converting a DNS problem from a GPL thread pool
from around 2000 to j.u.c. The current code ignores exceptions, is not
very maintainable and I've decided that it would be best to start
over. One caveat: The program uses recursion and a new thread for
every iteration.

The goal however necessary is to get every 'A record' , determine if
the 'A record' is actually a 'DN record' , and if so, start over -
perhaps recursively. The result being a List of every host and ip from
a given DNS server.

I'm looking at the jcip TransformingSequential example, and thinking
how I could apply that to this problem. I've also been thinking about
perhaps dividing the 'A record' and 'DN record' into different
CompletionService's . Nothing seems right yet. Here's the old code, an
inner class - the only relevant thing in the parent class is that it
inits the 'DirContext ictx'. Any ideas?

    // fugly code
    private class SearchDomain implements Runnable {

        private boolean recursive;
        private Map<String, String> collection;
        private String domain;

        public SearchDomain(String domain, Map<String, String> collection,
                boolean recursive) {

            this.domain = domain;
            this.collection = collection;
            this.recursive = recursive;

        public void run() {

            if (!domainsVisitados.contains(domain)) {


                try {
                    NamingEnumeration hostEnumeration = ictx.list(domain);

                    // get the hosts with their names and ip's.
                    while (hostEnumeration.hasMore()) {

                        String host = null;
                        host = ((NameClassPair) hostEnumeration.next())

                        // Get 'A Records'
                        Attributes a = ictx.getAttributes(host,
                                new String[] { "A" });

                        if (a.get("A") != null) {
                            String ip = a.get("A").get().toString();
                            collection.put(host, ip);
                        if (recursive) {
                            // find which ones are DNS e create new thread
                            Attributes aDNS = ictx.getAttributes(host,
                                    new String[] { "NS" });
                            NamingEnumeration allDNS = aDNS.getAll();

                            while (allDNS.hasMore()) {
                                Attribute attr = (Attribute) allDNS.next();
                                NamingEnumeration values = attr.getAll();

                                // put the host and ip into the 'collection'
                                while (values.hasMore()) {
                                    String dns = values.next().toString();
                                    pool.assign(new SearchDomain(dns,
                                            collection, recursive));
                } catch (Exception e) {

More information about the Concurrency-interest mailing list