so, lets say I have a thread that looks like this:

public run() {
   boolean active = true;
   while (active) {
     //do some action that takes a really long time

Is there any way I can directly stop and destroy this thread in the middle of the action which takes a really long time to complete? Basically, I want to instantly kill this thread. The other way that I see is to set active to false, but the thread wont actually stop until it completes its current action.

It may be hard to imagine where this is a problem, but the action I'm speaking of is a ftp transfer of a very large file, using this thread. I need a way to abort the transfer, instantly. Suggestions?

Edited by TheWhite: n/a

6 Years
Discussion Span
Last Post by ~s.o.s~
Featured Replies
  • 1
    ~s.o.s~ 2,560   6 Years Ago

    Or not; read [URL="http://download.oracle.com/javase/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html"]why Are Thread.stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnExit Deprecated?[/URL] Read More


Call stop() method to kiill the thread.

import java.lang.Runnable;

public class T implements Runnable{

   Thread timer = null;

   public void start() {
   if(timer == null)
        timer = new Thread(this);
   public void stop() {
        timer = null;

   public void run( ) {

        while (timer != null) {
        try {Thread.sleep(100);} catch (InterruptedException e) {}
     		// do something
        timer = null;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.