?? synccounter2.java
字號:
class SyncCounter2
{
public static void main(String[] args){
Num num = new Num();
Thread counter1 = new Counter(num);
Thread counter2 = new Counter(num);
for( int i=0; i<10; i++ ){
num.testEquals();
try{
Thread.sleep(100);
}catch(InterruptedException e){
}
}
}
}
class Num
{
private int x=0;
private int y=0;
synchronized void increase(){
x++;
y++;
}
synchronized void testEquals(){
System.out.println( x + "," + y +" :" + (x==y));
}
}
class Counter extends Thread
{
private Num num;
Counter( Num num ){
this.num = num;
this.start();
}
public void run(){
while(true){
num.increase();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -