title: HandlerThread should i override run()?
body: <p>I'm trying to use the HandlerThread class to manage thread in my application. The following code is working great : </p>
  
  <pre><code>public class ThreadA extends HandlerThread
  {
      private void foo()
      {
          //do something
      }
  
      private void bar()
      {
          //Do something else
      }
  
      @Override
      public boolean handleMessage(Message msg) {
          switch(msg.what)
          {
              case 1:
              {
                  this.foo();
                  break;
              }
  
              case 2:
              {
                  this.bar();
                  break;
              }
          }
          return false;
      }
  
      @Override
      protected void onLooperPrepared()
      {
          super.onLooperPrepared();
          synchronized (this) {
              this.AHandler = new Handler(getLooper(),this);
              notifyAll();
          }
      }
  }
  </code></pre>
  
  <p>1- Should i override the run() method ? In a "classic" thread most of the code is located in the run method.</p>
  
  <p>2- Lets imagine i need my foo() method to be a infinite process (getting a video streaming for example).
  What's the best solution ?  </p>
  
  <ul>
  <li>Overriding run with my foo() code ?</li>
  <li><p>Simply adding a sleep(xxx) in foo() :</p>
  
  <p>private void foo()
      {
          //do something
          sleep(100);
          foo();
      }</p></li>
  </ul>
  
  <p>-Using a delayed message like :   </p>
  
  <pre><code>private void foo()
  {
      //do something
      handler.sendEmptyMessageDelayed(1,100);
  }
  </code></pre>
  
  <p>PS : Asynctask will not cover my need , so do not bother to tell me to use it.</p>
  
  <p>Thanks</p>