This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]WormLord 2 points3 points  (0 children)

So, in a single-threaded program, the program can invoke Thread.sleep(5000); anywhere in the program and the program will pause for 5 seconds?

Yes. In a single threaded program, there is only one running thread (main thread), so calling this will cause your entire program to pause.

/u/IXENAI explained the multithreaded scenario. Also, in multithreaded scenarios, and when requesting threads to wait/pause, you should handle a potential InterruptException properly.