Skip to content

Instantly share code, notes, and snippets.

@gkastrinis
Last active January 31, 2016 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkastrinis/56a65658469edb778b31 to your computer and use it in GitHub Desktop.
Save gkastrinis/56a65658469edb778b31 to your computer and use it in GitHub Desktop.
PingUoA
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
public class Main {
final static int SLEEP_TIME = 7;
public static void main(String[] args) {
while (true) {
try {
final HttpURLConnection urlConn = (HttpURLConnection) new URL("http://www.uoa.gr").openConnection();
urlConn.setConnectTimeout(1000 * 10);
urlConn.connect();
if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK)
System.out.println("Ping successful!!!");
} catch (final SocketTimeoutException e) {
System.err.print("timeout...");
} catch (IOException e) {
e.printStackTrace();
}
try {
System.err.println(" (wait...)");
TimeUnit.MINUTES.sleep(SLEEP_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment