package com.dome;
public class Thread01 {
private volatile static int a =10;
Thread td1 = new Thread(){
public void run(){
for(int i=0;i<3;i++){
a = a+1;
System.out.println(i+"td1:="+a);
}
}
};
Thread td2 = new Thread(){
public void run(){
for(int i=0;i<3;i++){
a -=1;
System.out.println(i+"td2:="+a);
}
}
};
public static void main(String[] args) {
Thread01 th = new Thread01();
th.td1.start();
th.td2.start();
}
}
0td1:=9
0td2:=9
1td1:=10
1td2:=9
2td1:=10
2td2:=9
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
ringa_lee