Call the interrupt() method on your thread. This will cause the sleep to be cancelled and an InterruptedException will be thrown.
More Related Contents:
- Difference between wait() and sleep()
- When does Java’s Thread.sleep throw InterruptedException?
- Difference between “wait()” vs “sleep()” in Java
- How to properly stop the Thread in Java?
- Why is spawning threads in Java EE container discouraged?
- wait until all threads finish their work in java
- Volatile vs Static in Java
- How can I pass a parameter to a Java Thread?
- Choose between ExecutorService’s submit and ExecutorService’s execute
- Updating UI from different threads in JavaFX
- How to demonstrate java multithreading visibility problems?
- java.lang.IllegalMonitorStateException: object not locked by thread before wait()?
- What are the main uses of yield(), and how does it differ from join() and interrupt()?
- ScheduledExecutorService Exception handling
- How does Java makes use of multiple cores?
- How to debug a multi-threaded app in IntelliJ?
- Prevent Swing GUI locking up during a background task
- When should I use a CompletionService over an ExecutorService?
- Multiple bouncing balls thread issue
- Why do InterruptedExceptions clear a thread’s interrupted status?
- Methods that Clear the Thread.interrupt() flag
- How to shutdown an ExecutorService?
- Do two synchronized methods execute simultaneously
- Java, divide incoming work uniformly via hashing in multithreaded evnironments
- Execution order of multiple threads
- How does Keep-alive work with ThreadPoolExecutor?
- Setting Ideal size of Thread Pool [duplicate]
- What makes the execution order of threads unpredictable?
- Why is Thread.stop() so dangerous
- Updating your UI and forcibly waiting before continuing JavaFX