/* Author: Julie Romm * Course: COM3336 * Professor: Karl Lieberherr * Homework 3, part 2 */ /* File: URLCycle.java * Classes implemented: URLCycle * * Purpose: * This class implements an infinite loop within which * 3 threads get created: a thread for accessing a ULR, * a thread for timing out the first thread, and * a thread for concurrent execution of the first two threads. * After concurrent thread is started, the current thread * goes to sleep for the INTERVAL amount of milliseconds. */ import java.io.*; import java.util.*; public class URLCycle extends Thread { private String urlpath; private URLThread urlthread; private TimeOutThread timeoutthread; private ConcurrentThread concthread; private boolean status = false; //constructor public URLCycle(String urlpath){ //System.out.println("URLCycle constructor"); this.urlpath = urlpath; } public void run() { for (;;) { urlthread = new URLThread(urlpath); timeoutthread = new TimeOutThread(urlthread); concthread = new ConcurrentThread(urlthread, timeoutthread); concthread.start(); try { concthread.join(); } catch (InterruptedException e) { System.out.println("URLCycle: " + e); } status = concthread.getStatus(); if (status == false) { System.out.println("Could not get the page at url " + urlpath); } try {Thread.sleep((long)(WebWatch.INTERVAL));} catch (InterruptedException e){}; } } }