I do a wait for 5 seconds in a spring boot method and i'm getting a connection timed out exception.
@PostMapping(value="/api/stt", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity endPoint(@RequestBody String payload) throws Exception {
...
int delay = 5000;
long start = System.currentTimeMillis();
while(start >= System.currentTimeMillis() - delay);
...
}
java.net.ConnectException: Connection timed out: connect
at java.base/sun.nio.ch.Net.connect0(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.connect(Net.java:579) ~[na:na]
at java.base/sun.nio.ch.Net.connect(Net.java:568) ~[na:na]
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:633) ~[na:na]
at net.schmizz.sshj.SocketClient.connect(SocketClient.java:126) ~[sshj-0.27.0.jar:0.27.0]`
I already tried wait and Thread.sleep as well as TimeUnit.SECONDS.sleep(5); and when i do a post with postman i get "Error: socket hang up" without any exception in Intellij.
Any help would be appreciated Postman screenshot
The issue was that i created a file in target directory using file.createNewFile() and intellij auto reload restarts the application because of the new file in the classpath which cuts the connection when there's enough time which is provided by the Thread.sleep(5000).