title: Synchronized method in android
body: <p>You might think that this question is duplicate of <a href="https://stackoverflow.com/questions/31652489/java-synchronized-method">this</a> one but no answers of that question helps me for understanding <code>synchronized</code> method in android. I searched a lot on google for understanding <code>synchronized</code> methods and i found some answer but they didn't help me to perfectly understand <code>Synchronized</code> methods because no answer has any perfect practical example.</p>
  <p>I have tried to understand <code>synchronized</code> method by implement 2 <code>synchronized</code> methods in my code and executing them concurrently but i am failed in properly implementing them. So, please provide explanation of <code>synchronized</code> method with <strong>simple example</strong> so, others like me also can understand it simply and in a faster way.</p>
  <h1><strong>UPDATE</strong></h1>
  <p>I am not sure i am going in right direction or not but i have tried following code which have 2 synchronized methods.</p>
  <pre><code>synchronized void add() {
      counter++;
      Log.e(&quot;JK&quot;, String.valueOf(counter));
  }
  
  synchronized void minus() {
      counter--;
      Log.e(&quot;JK&quot;, String.valueOf(counter));
  }
  </code></pre>
  <p>and i have called this methods in two different threads using below code.</p>
  <pre><code>new Handler().postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      synchronized (counter++) {
                          add();
                      }
                  }
              },500);
              new Handler().postDelayed(new Runnable() {
                  @Override
                  public void run() {
                      minus();
                  }
              },1000);
  </code></pre>