??????????????
????/*
????*????????????
????*???????????????????
????*/
????public class ThreadDemo3{
????private static boolean flags=false;
????public static void main(String[]args){
????class Person{
????public String name;
????private String gender;
????public void set(String name??String gender){
????this.name=name;
????this.gender=gender;
????}
????public void get(){
????System.out.println(this.name+"...."+this.gender);
????}
????}
????final Person p=new Person();
????new Thread(new Runnable(){
????public void run(){
????int x=0;
????while(true){
????synchronized(p){
????if(flags)
????try{
????p.wait();
????}catch(InterruptedException e){
????//TODO Auto-generated catch block
????e.printStackTrace();
????};
????if(x==0){
????p.set("????"??"??");
????}else{
????p.set("lili"??"nv");
????}
????x=(x+1)%2;
????flags=true;
????p.notifyAll();
????}
????}
????}
????}).start();
????new Thread(new Runnable(){
????public void run(){
????while(true){
????synchronized(p){
????if(!flags)
????try{
????p.wait();
????}catch(InterruptedException e){
????//TODO Auto-generated catch block
????e.printStackTrace();
????};
????p.get();
????flags=false;
????p.notifyAll();
????}
????}
????}
????}).start();
????}
????}
????????????????
????public class ThreadDemo4{
????private static boolean flags=false;
????public static void main(String[]args){
????class Goods{
????private String name;
????private int num;
????public synchronized void produce(String name){
????if(flags)
????try{
????wait();
????}catch(InterruptedException e){
????//TODO Auto-generated catch block
????e.printStackTrace();
????}
????this.name=name+"????"+num++;
????System.out.println("??????...."+this.name);
????flags=true;
????notifyAll();
????}
????public synchronized void consume(){
????if(!flags)
????try{
????wait();
????}catch(InterruptedException e){
????//TODO Auto-generated catch block
????e.printStackTrace();
????}
????System.out.println("??????******"+name);
????flags=false;
????notifyAll();
????}
????}
????final Goods g=new Goods();
????new Thread(new Runnable(){
????public void run(){
????while(true){
????g.produce("???");
????}
????}
????}).start();
????new Thread(new Runnable(){
????public void run(){
????while(true){
????g.consume();
????}
????}
????}).start();
????}
????}
???????????????2
????public class ThreadDemo4{
????private static boolean flags=false;
????public static void main(String[]args){
????class Goods{
????private String name;
????private int num;
????public synchronized void produce(String name){
????while(flags)
????try{
????wait();
????}catch(InterruptedException e){
????//TODO Auto-generated catch block
????e.printStackTrace();
????}
????this.name=name+"????"+num++;
????System.out.println(Thread.currentThread().getName()+"??????...."+this.name);
????flags=true;
????notifyAll();
????}
????public synchronized void consume(){
????while(!flags)
????try{
????wait();
????}catch(InterruptedException e){
????//TODO Auto-generated catch block
????e.printStackTrace();
????}
????System.out.println(Thread.currentThread().getName()+"??????******"+name);
????flags=false;
????notifyAll();
????}
????}
????final Goods g=new Goods();
????new Thread(new Runnable(){
????public void run(){
????while(true){
????g.produce("???");
????}
????}
????}??"?????????").start();
????new Thread(new Runnable(){
????public void run(){
????while(true){
????g.produce("???");
????}
????}
????}??"?????????").start();
????new Thread(new Runnable(){
????public void run(){
????while(true){
????g.consume();
????}
????}
????}??"?????????").start();
????new Thread(new Runnable(){
????public void run(){
????while(true){
????g.consume();
????}
????}
????}??"?????????").start();
????}
????}
????/*
???????????????????******???????48049
???????????????????....???????48050
???????????????????******???????48050
???????????????????....???????48051
???????????????????******???????48051
???????????????????....???????48052
???????????????????******???????48052
???????????????????....???????48053
???????????????????******???????48053
???????????????????....???????48054
???????????????????******???????48054
???????????????????....???????48055
???????????????????******???????48055
????*/