There is no good way to stop a thread instantly.
There is Thread.stop(), but it is dangerous and deprecated. Don't use it, unless:
you fully understand the problems that make it dangerous,
you have thoroughly analyzed your code and determined that the problems do not apply and / or the risks are acceptable, and
you don't care that your application may end up stuck at a some version of Java if / when the method is removed1.
There was Thread.stop(Throwable) but it was equally dangerous2, deprecated and was removed3 in Java 11.
There is Thread.interrupt(), but there is no guarantee that the thread will stop quickly, or even stop at all. The behavior will depend on whether the application thread code has been designed to notice and correctly respond to interrupts. (See below.)
There is the approach of writing the thread to periodically check a flag; see this answer. (See below.)
The "check a flag" and interrupt() approaches are largely the same. In both cases, the thread that expects to be interrupted needs to regularly check; e.g. by calling interrupted() or isInterrupted() or by checking a flag.
The difference between the approaches is tha
Do not under any circumstances use Thread.stop - if you are asking this question then you do not understand the Java threading model enough to safely use it.
The details, for the curious, are here: Java Thread Primitive Deprecation
If you get really good at Java concurrency, then you will understand why you should never use it, and that even if it's entirely safe within your own code, it makes your code contaminated and unusable by anyone else. Instead you will probably end up use the boolean variable trick or some other pattern to tell a thread when it should finish up and then exit.
Do not use Thread.stop. Ever.