-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPing.java
More file actions
37 lines (30 loc) · 1.06 KB
/
Copy pathPing.java
File metadata and controls
37 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package networking;
import java.io.IOException;
import java.net.InetAddress;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class Ping {
public static void main(String[] args) throws Exception {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
final InetAddress adress = InetAddress.getByName("192.168.22.7");
executor.scheduleWithFixedDelay(new IsReachable(adress), 0, 2, TimeUnit.SECONDS);
}
private static class IsReachable implements Runnable {
private final InetAddress adress;
public IsReachable(InetAddress address) {
this.adress = address;
}
@Override
public void run() {
try {
if (adress.isReachable(2000)) {
System.out.println("reachable");
} else {
System.out.println("not reachable");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}