12 方法上的 synchronized

12 方法上的 synchronized

//普通方法上加synchronized
class Test{
public synchronized void test() {

}
}
//等价于
class Test{
public void test() {
synchronized(this) {

}
}
}
//静态方法上加synchronized
class Test{
public synchronized static void test() {
}
}
//等价于
class Test{
public static void test() {
synchronized(Test.class) {

}
}
}
posted @ 2023-06-29 23:19  渺阴丶  阅读(16)  评论(0)    收藏  举报