多个线程操作一个变量(synchronized)

2021-05-29 01:03

阅读:381

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();


}
}


评论


亲,登录后才可以留言!