title: java method prevent from concurrent access
body: <p>How can I prevent from concurrent access. I have code like this</p>
  
  <pre><code>public class MC implements Runnable {
  
      public void run() {
          sync();
      }
  
      public static void main(String p[]){
          MC mc = new MC();
          MC mc2 = new MC();
          MC mc3 = new MC();
          MC mc4 = new MC();
          Thread t = new Thread(mc);
              t.start();
              Thread t2 = new Thread(mc2);
              t2.start();
              Thread t3 = new Thread(mc3);
              t3.start();
              Thread t4 = new Thread(mc4);
              t4.start();
      }
  
      private synchronized void sync(){
          try {
              System.out.println(System.currentTimeMillis());
              Thread.sleep(10000);
          } catch (InterruptedException ex) {
              ex.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>and I am getting output like this</p>
  
  <pre><code>1307082622317
  1307082622317
  1307082622317
  1307082622317
  BUILD SUCCESSFUL (total time: 11 seconds)
  </code></pre>
  
  <p>any advice?</p>