Java中不同线程调用synchronized方法的问题
一个含有synchronized修饰符方法的类
public class ForTest {
private int i = 0;
public synchronized void fun1(){
i = 100;
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("fun1: i = " + i);
}
public void fun2(){
i = i + 1;
System.out.println("fun2: i = " + i);
}
}
两个线程类
public class MyThread1 implements Runnable {
private ForTest ft = null;
public MyThread1(ForTest ft){
this.ft = ft;
}
public void run() {
ft.fun1();
}
编辑推荐:
温馨提示:因考试政策、内容不断变化与调整,长理培训网站提供的以上信息仅供参考,如有异议,请考生以权威部门公布的内容为准! (责任编辑:长理培训)
点击加载更多评论>>