simple timeout code java code example
Example 1: java time code
final long startTime = System.currentTimeMillis();
for (int i = 0; i < length; i++) {
// Do something
}
final long endTime = System.currentTimeMillis();
System.out.println("Total execution time: " + (endTime - startTime));
Example 2: java socket timeout
Socket socket = new Socket(); // 1000 milliseconds
socket.connect(new InetSocketAddress(ipAddress, port), 1000);