日期:2014-05-20 浏览次数:20671 次
package com;
public class Test3 extends Thread{
XX xx;
int start;
public Test3(XX xx,int start){
this.xx=xx;
this.start=start;
}
public void run(){
int num=0;
for(int i=start;i<start+500;i++){
num+=i;
}
if(this.start==0){
xx.setNum1(num);
xx.setFlag1(true);
}else if(this.start==500){
xx.setNum2(num);
xx.setFlag2(true);
}
if(xx.isFlag1()&&xx.isFlag2()){
System.out.println(xx.getNum1()+xx.getNum2());
}
}
public static void main(String[] args) {
XX xx=new XX();
new Test3(xx, 0).start();
new Test3(xx, 500).start();
}
}
class XX{
public int num1=0;
public int num2=0;
public boolean flag1=false;
public boolean flag2=false;
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}
public boolean isFlag1() {
return flag1;
}
public void setFlag1(boolean flag1) {
this.flag1 = flag1;
}
public boolean isFlag2() {
return flag2;
}
public void setFlag2(boolean flag2) {
this.flag2 = flag2;
}
}
package a.b.test;