gpt4 book ai didi

java - 同步与同步的区别

转载 作者:行者123 更新时间:2023-12-01 16:48:25 26 4
gpt4 key购买 nike

thisExample.this 是同一个对象吗?

例如synchronized 中的调用 thisExample.class 是同一个对象吗?

class Example {
public Example() {
synchronized(this) {
// some code
}
}
}


class Example {
public Example() {
synchronized(Example.class) {
// some code
}
}
}

最佳答案

不,this 使用当前对象作为监视器,但 Example.class 使用 Example.class 作为监视器。

关于java - 同步与同步的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45373204/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com