I personally do that kind of thing:

class MyThread extends Thread {
  private boolean done;

  public void run() {
    while (true) {
      synchronized (this) {
        if (done) break;
      }

      /* do a small part of the heavy work */
    }

    /* cleanup, close files, etc.. */
  }

  /* Call release() to stop/cancel */
  public void release() {
    synchronized (this) {
      done = true;
    }

    /* Wait for run() to return */
    try { join(); } catch (InterruptedException e) { }
  }
}

Olivier

On 06/17/2010 12:42 PM, Abdul Mateen wrote:
> Hi,
> 
> Thread.stop() and destroy were risk in the Threading class. the method I
> use to stop thread is to use return; statement where I want to stop the
> thread.
> 
> like
> 
> new Thread ( new Runnable() {
> 
>  public void run(){
>     if ( condition ) return; // this will stop the thread.
> }
> 
> }).start();
> 
> On Thu, Jun 17, 2010 at 3:37 PM, brijesh masrani
> <[email protected] <mailto:[email protected]>> wrote:
> 
>     Hello,
> 
>     I want to stop currently running thread but -Thread.stop()
>      -Thread.destroy() are DEPRECATED so can any one tell me how to stop
>     the Thread
> 
> 
> 
>     -- 
>     Regards,
>     Brijesh Masrani
> 
>     -- 
>     You received this message because you are subscribed to the Google
>     Groups "Android Developers" group.
>     To post to this group, send email to
>     [email protected]
>     <mailto:[email protected]>
>     To unsubscribe from this group, send email to
>     [email protected]
>     <mailto:android-developers%[email protected]>
>     For more options, visit this group at
>     http://groups.google.com/group/android-developers?hl=en
> 
> 
> 
> 
> -- 
> Regards,
> Abdul Mateen,
> Software Engineer at Rounded Labs Ltd.
> Linux Administrator at Addictive Mobility Inc
> Mobile : +92-333-3265875.
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to