????????????????synchronized?????????????С????ε??Χ??????С???????????????????????????????????????м?С????????????????????????????????????????????????????????????????????????????????л?????????????????????????????????????

??????????????????????ж?new?????Sync??????????????????Sync????????????????????????????????????synchronized?????????Ρ?

???????????????????????′???????????????????Sync?????

class MyThread extends Thread {

 private Sync sync;

 public MyThread(Sync sync) {
  this.sync = sync;
 }

 public void run() {
  sync.test();
 }
}

public class Main {

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

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

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

??????????????????synchronized??????synchronized????ζ????????á?

??????????????????????δ????????????????????????????δ?????????new???Sync?????????????test???????????????С?

??????????????????????????????????磬synchronized??????????????static final??????????????????????????????????????????synchronized???????????Class????

class Sync {

 public void test() {
  synchronized (Sync.class) {
   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????..

?????????????synchronized(Sync.class)????????????Ч????

????????static synchronized???????static??????????????????????????????????????this????????????static synchronized????????????????????????????Ρ?