wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Spawning and monitoring a thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Spawning and monitoring a thread" Watch "Spawning and monitoring a thread" New topic
Author

Spawning and monitoring a thread

Bryan Welch
Ranch Hand

Joined: Jan 13, 2000
Posts: 32
Summary: I need to create a child thread/process that tries to reach an outside URL, get some info, and return. That child needs to be monitored so that if it doesn't return with results within five seconds, it parent gives up and goes on.
Now, with that in mind, here's the situation:
I have a servlet that creates a web page with local information, weather, and stock quotes. The weather and stock quotes come from an outside company. When the DNS got messed up Friday, the weather/stock URL was unreachable, and since it was a DNS timeout happening this took over five minutes. That stopped our web page from being displayed at all. The process got stalled on these lines:
HttpMessage message = new HttpMessage( url );
InputStream data = message.sendPostMessage( weatherInfo );
What's the best way to create a child process for this, monitor it, and give up after a set time. This would make it so that if the weather or stock info isn't available, a message could be shown like "Weather not available." without waiting excessively. If the weather/stock URL is reached and the server is down, I get a reply anyway and the message above is shown. There's only a problem if I don't get a reply, i.e. DNS problems. Changing the DNS timeout isn't an option here, unfortunately.
So, if anyone has recommendations or knows of some code that does something like this, I'd greatly appreciate the help.

----<br />Bryan Welch<br />bwelch42@yahoo.com
Bryan Welch
Ranch Hand

Joined: Jan 13, 2000
Posts: 32
Another idea to solve this problem: What about using getHostByName() to see if the URL can be resolved? Haven't found a java version of this, but it's a thought...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spawning and monitoring a thread
 
Similar Threads
Child class calls method in Parent class.
interrupting a Socket.accept()
DBTester and DBTestRunner in Max's book
Doubt in Servlet threading
Mike Gershman's Q