FileDocCategorySizeDatePackage
URLPingTask.javaAPI DocExample1037Sun Mar 14 10:54:40 GMT 2004javathreads.examples.ch11.example1

URLPingTask

public class URLPingTask extends TimerTask

Fields Summary
URL
url
URLUpdate
updater
Constructors Summary
public URLPingTask(URL url)

        this(url, null);
    
public URLPingTask(URL url, URLUpdate uu)

        this.url = url;
        updater = uu;
    
Methods Summary
public voidrun()

        if (System.currentTimeMillis() - scheduledExecutionTime() > 5000) {
            // Let the next task do it
            return;
        }
        try {
            HttpURLConnection huc = (HttpURLConnection) url.openConnection();
            huc.setConnectTimeout(1000);
            huc.setReadTimeout(1000);
            int code = huc.getResponseCode();
            if (updater != null)
                updater.isAlive(true);
        } catch (Exception e) {
            if (updater != null)
                updater.isAlive(false);
        }