I have written a program which launches a new thread and within this thread it attempts to download a webpage at a specified URL. I use the "join" method to ensure the thread finishes before the program can move on.
If the server hosting the page hangs or for some other reason the page takes a significant time to download I want to be able to "cancel" the thread and move on.
The code is as follows:
// Create a new crawl object
Crawl newCrawlObj;
newCrawlObj = new Crawl();
Thread newCrawlThread = new Thread(newCrawlObj);
newCrawlThread.start();
// Wait until the Crawl thread has finished before starting another
try {newCrawlThread.join();}
catch (InterruptedException ex) {ex.printStackTrace();}
So, for arguments sake, is there a way to say "if the thread takes longer than 20 seconds "cancel" the thread and continue execution?
Thanks
-Myles