<p>Here is my problem: I've got a dialog with some parameters that the user can change (via a spinner for example). Each time one of these parameters is changed, I launch a thread to update a 3D view according to the new parameter value. 
If the user changes another value (or the same value again by clicking many times on the spinner arrow) while the first thread is working, I would like to abort the first thread (and the update of the 3D view) and launch a new one with the latest parameter value.</p>

<p>How can I do something like that?</p>

<p>PS: There is no loop in the <code>run()</code> method of my thread, so checking for a flag is not an option: the thread updating the 3D view basically only calls a single method that is very long to execute. I can't add any flag in this method asking to abort either as I do not have access to its code.</p>

The thread that is updating the 3D view should periodically check some flag (use a
```
volatile boolean
```
) to see if it should terminate.  When you want to abort the thread, just set the flag.  When the thread next checks the flag, it should simply break out of whatever loop it is using to update the view and return from its
```
run
```
method.
If you truly cannot access the code the Thread is running to have it check a flag, then there is no safe way to stop the Thread.  Does this Thread ever terminate normally before your application completes?  If so, what causes it to stop?
If it runs for some long period of time, and you simply must end it, you can consider using the deprecated
```
Thread.stop()
```
method.  However, it was deprecated for a good reason.  If that Thread is stopped while in the middle of some operation that leaves something in an inconsistent state or some resource not cleaned up properly, then you could be in trouble.  Here's a note from the
documentation
:
This method is inherently unsafe.
  Stopping a thread with Thread.stop
  causes it to unlock all of the
  monitors that it has locked (as a
  natural consequence of the unchecked
  ThreadDeath exception propagating up
  the stack). If any of the objects
  previously protected by these monitors
  were in an inconsistent state, the
  damaged objects become visible to
  other threads, potentially resulting
  in arbitrary behavior. Many uses of
  stop should be replaced by code that
  simply modifies some variable to
  indicate that the target thread should
  stop running. The target thread should
  check this variable regularly, and
  return from its run method in an
  orderly fashion if the variable
  indicates that it is to stop running.
  If the target thread waits for long
  periods (on a condition variable, for
  example), the interrupt method should
  be used to interrupt the wait. For
  more information, see
Why are
  Thread.stop, Thread.suspend and
  Thread.resume Deprecated?