简体   繁体   English

Java中的同步块

[英]Synchronized block in java

I came across the code: 我碰到了代码:

synchronized(Account.this)   
{}   

where Account is a class. 其中Account是一类。
Does Account.this mean any current instance of class Account? Account.this是否表示Account类的任何当前实例?

This would probably be from an inner class of Account. 这可能来自Account的内部类。

class Account {
  class InnerAccount {
    ...
    synchronized(Account.this) {
    }
  }
}

Normally it is used inside of an inner class: It means the this instance of the outer Account class. 通常,它在内部类内部使用:这表示外部Account类的this实例。

Writing this by itself will return the instance of the inner class, not the outer class. 单独编写this将返回内部类的实例,而不是外部类的实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM