??????Java?У?synchronized?????????????????????????????????????£?????synchronized????β?????????????С?Synchronized?????????????????????????????????

?????????????????????????????μ???synchronized???′???????????δ???

class Sync {

 public synchronized void test() {
  System.out.println("test???..");
  try {
   Thread.sleep(1000);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
  System.out.println("test????..");
 }
}

class MyThread extends Thread {

 public void run() {
  Sync sync = new Sync();
  sync.test();
 }
}

public class Main {

 public static void main(String[] args) {
  for (int i = 0; i < 3; i++) {
   Thread thread = new MyThread();
   thread.start();
  }
 }
}

???????н????

????test???..
????test???..
????test???..
????test????..
????test????..
????test????..

?????????????????????????????????????????test?????????test??????????synchronized?????????????????????ò??synchronized??????á?

??????test??????????£?

 public void test() {
  synchronized(this){
   System.out.println("test???..");
   try {
    Thread.sleep(1000);
   } catch (InterruptedException e) {
    e.printStackTrace();
   }
   System.out.println("test????..");
  }
 }

???????н????

????test???..
????test???..
????test???..
????test????..
????test????..
????test????..

??????л?????????????п???synchronized???????á?

??????????synchronized(this)?????static??synchronized??????????static synchronized???????????????????????????????????????????????Ρ?

??????????????????????????????Java????????synchronized????????????????????synchronized???????????????????????????????????synchronized????????????????????this??

??????synchronized?????????????????????????????????????????????????????????????????????θ?????????????????????????????