Question: I wrote a thread, it is taking too much time to execute and it seems it is not completely done. I want to stop the thread gracefully. Any help ?

Answer: 
Make a volatile boolean `stop` somewhere. Then in the code that runs in the thread, regularly do

```
 if (stop) // end gracefully by breaking out of loop or whatever

```

To stop the thread, set `stop` to `true`.

I think you must do it manually this way. After all, only the code running in the thread has any idea what is and isn't graceful.
For a thread to stop itself, no one seems to have mentioned (mis)using exception:

```
abstract class SelfStoppingThread extends Thread {

    @Override
    public final void run() {
        try {
            doRun();
        } catch (final Stop stop) {
            //optional logging
        }
    }

    abstract void doRun();

    protected final void stopSelf() {
        throw new Stop();
    }

    private static final class Stop extends RuntimeException {};

}

```

A subclass just need to override doRun() normally as you would with a Thread, and call stopSelf() whenever it feels like it wants to stop. IMO it feels cleaner than using a flag in a while loop.