一、作用:保证被它修饰的方法或代码块在任意时刻只能有一个线程执行
二、用法:
- 修饰实例方法
synchronized void method() {
}
- 修饰静态方法
synchronized static void method() {
}
- 修饰代码块
synchronized (this) {
}
一、作用:保证被它修饰的方法或代码块在任意时刻只能有一个线程执行
二、用法:
synchronized void method() {
}
synchronized static void method() {
}
synchronized (this) {
}