Search code examples
javamultithreadingdnsobserver-pattern

Multithreading or observer pattern when waiting for dns lookup?


I'm designing a system in java which utilizes a dns lookup class.

My question is, when calling the class's dnsLookup(), whether to do it in a new thread or use the observer pattern and let the dns class tell me when it's done.

This isn't a problem as long as the lookup returns a value almost instantly but when it takes a few seconds (when it doesn't get a response), I don't want to freeze the GUI while waiting.

So, new thread or observer. Appreciate some good links on the subjects as well.

Thanks beforehand - Dennis


Solution

  • You will have to employ both the observer pattern and more than one thread. There's no way to have the DNS invoking callback method in the same thread.