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)
如果我错了,请忽略这个问题.
public synchronized void addition() {...}
Run Code Online (Sandbox Code Playgroud)
相当于
public void addition() {
synchronized(this) { ... }
}
Run Code Online (Sandbox Code Playgroud)
现在,如果this
用另一个对象引用替换它,则将使用该另一个对象的监视器完成锁定.
归档时间: |
|
查看次数: |
481 次 |
最近记录: |