【问题标题】:If we make a method synchronized then all the instance method will be locked or only the synchronized methods will be locked? [duplicate]如果我们使一个方法同步,那么所有实例方法都会被锁定,还是只有同步方法会被锁定? [复制]
【发布时间】:2018-04-13 18:21:24
【问题描述】:

如果我们使一个方法同步,那么在执行该方法时所有实例方法都会被锁定,还是只有其他同步方法会被锁定?

【问题讨论】:

  • 不要把标题当作内容,至少要多补充一些信息

标签: java multithreading thread-safety


【解决方案1】:

好吧,如果同步方法是静态的,那么它将为所有实例同步,否则它将为调用它的特定对象同步。 如果一个对象试图访问同步方法并且该对象对该方法有两次调用,那么在第一次操作完成之前,第二次调用无法继续

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-04
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多