title: Synchronized keyword and static classes in java
body: <p>I was reading a threading tutorial that’s originally from (I believe) the IBM developerworks site.  In it they talked about the synchronized keyword and how a synchronized block of code is locked by the actual object, not the block of code itself.  </p>
  
  <p>For instance, in the code below the authors state that even though the static class ‘<code>Thingie</code>’s <code>setLastAccess</code> method is listed as synchronized, the two threads defined below it can each call <code>setLastAccess</code> simultaneously, because they’re using different values for thingie.  But if thingie is static won’t that mean they’re using the same value?</p>
  
  <p>Is it the case that the variable names only need be different, even if they're referring to the same object?</p>
  
  <pre><code>public class SyncExample {
      public static class Thingie {
          private Date lastAccess;
          public synchronized void setLastAccess(Date date) {
              this.lastAccess = date;
          }
      }
      public static class MyThread extends Thread {
          private Thingie thingie;
          public MyThread(Thingie thingie) {
              this.thingie = thingie;
          }
          public void run() {
              thingie.setLastAccess(new Date());
          }
      }
      public static void main() {
          Thingie thingie1 = new Thingie(),
          thingie2 = new Thingie();
          new MyThread(thingie1).start();
          new MyThread(thingie2).start();
      }
  } 
  </code></pre>