public class Widget {
public synchronized void doSomething () {
System.out.println(this.toString()+"---------------------");
}
}public class LoggingWidget extends Widget {
public synchronized void doSomething () {
System.out.println(this.toString()+ ": calling doSomething");
super.doSomething();
}
public static void main (String[] args) throws InterruptedException {
for (int i = 0; i < 2; i++) {
Thread thread = new Thread(() -> {
Widget widget = new LoggingWidget();
widget.doSomething();
});
thread.start();
}
}
}com.concyrrency.test.lock.LoggingWidget@2cb7a5c1: calling doSomething com.concyrrency.test.lock.LoggingWidget@2cb7a5c1--------------------- com.concyrrency.test.lock.LoggingWidget@77df833b: calling doSomething com.concyrrency.test.lock.LoggingWidget@77df833b---------------------

售后响应及时
7×24小时客服热线
数据备份
更安全、更高效、更稳定
价格公道精准
项目经理精准报价不弄虚作假
合作无风险
重合同讲信誉,无效全额退款