title: Thread won't enter synchronized block
body: <p>I have a Button in my android app which must run a continuous action while holding it down, for that I created an <code>onTouchListener</code> to handle such issue, my structure is when catching <code>ACTION_DOWN</code> event a thread with a while(true) loop runs, then when catching <code>ACTION_UP</code> event that thread stopped via <code>wait()</code> in order to resume it's looping again upon holding down, the problem is that when trying to execute <code>thread.wait()</code> the thread doesn't enter the synchronized block and doesn't wait, but it stops the execution of <code>runOnUIThread</code> which exists in that thread, and after I press any button after that the app crashes and gives me <code>ANR Exception : Input dispatching timed out</code>:</p>
  
  <pre><code>   // the thread declaratrion
      test = new Thread(new Runnable() {
  
          @Override
          public void run() {
  
              while (true) {
                  // still loops here
                  value = value + 1;
                  runOnUiThread(new Runnable() {
                      public void run() {
                          // doesn't go here anymore
                          mTextView.setText(Integer.toString(value));
                      }
                  });
                  // still loops here
                  synchronized (test) {
                      try {
                          Thread.sleep(150);
                      } catch (InterruptedException e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
                  }
  
              }
          }
      });
  
      // the onTouchListener
      case MotionEvent.ACTION_DOWN:
          if (!test.isAlive()) {
              synchronized (test) {
                  test.start();
              }
          } else {
              synchronized (test) {
                  test.notify();
              }
          }
          break;
      case MotionEvent.ACTION_UP:
          // accepts the action
          synchronized (test) {
              try {
                  // doesn't goes here
                  test.wait(); // doesn't execute
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
          break;
      default:
          break;
  </code></pre>