同步函数和同步块之间有什么区别?

ali*_*786 2 java multithreading locking synchronized

有什么区别

public synchronized void addition()
{
   //something;
}
Run Code Online (Sandbox Code Playgroud)

public void addtion()
{
     synchronized (//something)
     {
        //something;
     }
}
Run Code Online (Sandbox Code Playgroud)

如果我错了,请忽略这个问题.

NPE*_*NPE 5

public synchronized void addition() {...}
Run Code Online (Sandbox Code Playgroud)

相当于

public void addition() {
  synchronized(this) { ... }
}
Run Code Online (Sandbox Code Playgroud)

现在,如果this用另一个对象引用替换它,则将使用该另一个对象的监视器完成锁定.