/* Author: Julie Romm * Course: COM3336 * Professor: Karl Lieberherr * Homework 3, part 2 */ /* File: TimeOutThread.java * Classes implemented: TimeOutThread * * Purpose: * This class is used for timing out the thread supplied as * an argument to the constructor. */ import java.io.*; import java.util.*; public class TimeOutThread extends Thread { private int timeout = 30000; private boolean status = false; private URLThread urlthread; public TimeOutThread(URLThread urlthread) { this.urlthread = urlthread; } public boolean getStatus() { return status; } public void run() { try { sleep((long)(timeout)); } catch (InterruptedException e) { System.out.println("TimeOutThread was interrupted."); } urlthread.interrupt(); //if urlthread has not finished running yet, //it will fail. status = urlthread.getStatus(); } }