多个线程操作一个变量(synchronized)
2021-05-29 01:03
public class MainTest {
public static void main(String[] args) { /**
*
* 两个线程进行操作
*
*
*
*
*/
WindowSell2 windowSell2 = new WindowSell2();
new Thread(()->{
try {
for (int i = 0; i windowSell2.increade();
}
}catch (InterruptedException e){
}
},"A").start();
new Thread(()->{
try {
for (int i = 0; i windowSell2.decreade();
}
}catch (InterruptedException e){
}
},"B").start();
new Thread(()->{
try {
for (int i = 0; i windowSell2.decreade();
}
}catch (InterruptedException e){
}
},"C").start();
}
}