Interrupting or stopping a sleeping thread

java, multithreading, sleep

Solution

Call the interrupt() method on your thread. This will cause the sleep to be cancelled and an InterruptedException will be thrown.

Problem

How to stop or interrupt a sleeping thread in java.? I have a thread that syncs data and sleeps for 10 minutes in run() method, if i want to stop the sync by stopping the thread when it is sleeping.? How can this be achieved?

Original source

Related problems