public class GuaranteeOrder implements Runnable{
static int count = 0;
@Override
public void run() {
try{
Thread.sleep(100);
setCount();
System.out.println("count结果为:"+getCount()+"-"+Thread.currentThread().getName());
}catch(InterruptedException e){
e.printStackTrace();
}
}
public void setCount(){
count=count+1;
}
public int getCount(){
return count;
}
public static void main(String[] args){
GuaranteeOrder go = new GuaranteeOrder();
Thread ta = new Thread(go, "Thread-A");
Thread tb = new Thread(go, "Thread-B");
Thread tc = new Thread(go, "Thread-C");
ta.start();
try {
ta.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tb.start();
try {
tb.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
tc.start();
try {
tc.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}