package 对象及变量的并发访问2;
/**
* 锁重入支持继承的环境
* 锁重入也支持父子类继承的环境
*/
class Main{
public int i=10;
synchronized public void operateIMainMethodT28(){
try {
i--;
System.out.println("mian print i="+i);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
class SubT218 extends Main{
// private int i=10;
synchronized public void opersteISubMethodT218(){
try {
while (i>0){
i--;
System.out.println("sub print i="+i);
Thread.sleep(1000);
super.operateIMainMethodT28(); }
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
class MyThreadT218 extends Thread{
@Override
public void run() {
SubT218 subT218=new SubT218();
subT218.opersteISubMethodT218();
}
}
class RunT218{
public RunT218(){
MyThreadT218 myThreadT218=new MyThreadT218();
myThreadT218.start();
}
}
public class T2108 {
public static void main(String[] args) {
RunT218 runT218=new RunT218();
}
}
锁重入支持继承的环境——T2108
最新推荐文章于 2022-02-10 18:30:36 发布