How to create a java application that monitors a website

Posted on 2003-02-26
Medium Priority
Last Modified: 2012-05-04
Hi, all

I need to create a java application that can monitor a website. If the website is down, it will send emails to some persons. Could you please help me to do it? Thanks.
Question by:CodeLover
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Expert Comment

ID: 8029150
Open a URLConnection on its index. If you get an Exception - send email.

Accepted Solution

vfwood earned 200 total points
ID: 8029575
import java.io.*;
import java.net.*;

public class HttpMonitor extends Thread {
     // how long to wait between attempts..
     private final static int SECONDS_TO_WAIT = 4;

     // url we wish to monitor.
     private final static String urlToMonitor = "http://www.google.com/";

     // entry point into application
     public static void main (String[] args)     {
          new HttpMonitor().start();

     // this is called by start() in main() method
     public void run()     {
          boolean running = true;
          while (running)     {
               try     {
                    // causes current thread to sleep x milliseconds
                    sleep (SECONDS_TO_WAIT * 1000);

                    URL myurl = new URL(urlToMonitor);
                    URLConnection conn = myurl.openConnection();
                    BufferedReader br = new BufferedReader(
                              new InputStreamReader(
                    // we will hold webpage contents here
                    String buff = "";
                    // and store each line in this temporary var
                    String tmp = "";
                    // keep reading till returns null
                    while ((tmp = br.readLine()) != null) {
                         buff+= "\n" + tmp;
                    // at this point we have read the webpage into String buff
                    // perform any checks you want to here...
                    System.out.println(new java.util.Date() + "> read ok");
               } catch (Exception e)     {
                    // handle your own exceptions here...
                    System.out.println(new java.util.Date() + ">" + e);


comments should help

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question