>      I read somewhere that Thread.stop() is now deprecated. 
Yes, and it's very good.
> Now how on  earth do we stop a thread ?
Just allow it to exit from its run() method.

Try to use this pattern: pattern is (run() can be in Thread subclass or
in Thread Runnable))

private boolean runEnabled_ = true;
private Object stopsync_ = new Object();
public void run() {
 while(isRunEnabled())
  {
  ... // do things in your thread
  }
}
public void stop() // call this function from other thread when you want
to stop thread
 {  syncrhonized(stopsync_)   { runEnabled_ = false; } }
public boolean isRunEnabled()
 {
 boolean result;
 synchronized(stopsync_)  { result = runEnabled_; }
 return result;
 }

>      I thought the solution would be Thread.interrupt()
>      but that only works when the thread is sleeping, at least in JDK 1.1
>      documentation.
Yes, it is just to awake waiting, joining or sleeping thread.
>It seems to be idiocy to have a start method and not have a stop method. 
In single thread You can call method from outside but you cannot stop it
until it leaves (things like Ctrl-C do the trick but there is destroy()
method in Thread API that is the analog of such unnormal killer). What
do you think it is strange here?

See also
http://java.sun.com/products/jdk/1.2/docs/guide/misc/threadPrimitiveDeprecation.html 

Hope this help

Pavel

Reply via email to