public class TestThreadcomtrue {
public static void main(String [] srgs){
Persion i=new Persion();
new Thread(new Threadren(i)).start();
new Thread(new Threadr(i)).start();
}
}
class Threadren implements Runnable{
Persion q=new Persion();
Threadren(Persion q){this.q=q;}
public void run(){
q.get();
}
}
class Threadr implements Runnable{
Persion q=new Persion();
Threadr(Persion q){this.q=q;}
public void run(){
q.put();
}
}
class Persion{
String name,sex;
int i=1;
public synchronized void get(){
while(true){
if(i%2==0){
name="zs";
try{Thread.sleep(1);}catch(Exception e){}
sex="male";
}
else{
name="lg";
sex="famale";
}
i=(i+1)%2;
}
}
public synchronized void put(){
while(true){
System.out.println(name+" "+sex);
}
}
}