0

I'm writing a Java program and I want to pause a Thread when the user presses a button. Is there a predefined method I can call from outside of the Thread to temporarily pause the Thread for a set time or a method that just pauses the thread? I.o.w. a sort of '.sleep(int)' that could be called from outside of the Thread. Thanks.

  • 1
    There is no safe way to pause a thread ... apart from having the thread pause itself ... at a safe position. (There is `Thread.pause()` but it is deadlock-prone AND it is deprecated for removal in a future Java release.) – Stephen C Sep 05 '22 at 14:05
  • Do you want to pause for a time duration or when the user presses a button again? – Progman Sep 05 '22 at 14:05
  • Always search Stack Overflow thoroughly before posting. – Basil Bourque Sep 05 '22 at 16:38

0 Answers0