本帖最后由 枫儿 于 2013-10-11 11:24 编辑
毕老师12天-04说的代码,和视频的代码对比了几次 没看出啥问题呀,咋还是成片的打印,帮忙看看- class rec
- {
- private String name;
- private String age;
- private boolean flog=false;
- public synchronized void set (String name,String age)
- {
- if (flog)
- try{this.wait();}catch (Exception e){}
- this.name=name;
- this.age=age;
- flog=true;
- this.notify();
- }
- public synchronized void out()
- {
- if (!flog)
- try{this.wait();}catch(Exception e){}
- System.out.println(name+".........."+age);
- flog=false;
- this.notify();
- }
- }
- class intl implements Runnable
- {
- private rec r;
- intl(rec r)
- {
- this.r=r;
- }
-
- public void run()
- {
- int x=0;
- while (true)
- {
- if (x==0)
- r.set("make"+"Man");
- else
- r.set("丽丽"+"女");
- x=(x+1)%2;
- }
- }
- }
- class outou implements Runnable
- {
- private rec r;
- outou(rec r)
- {
- this.r=r;
- }
- public void run()
- {
- while (true)
- {
- r.out();
- }
- }
- }
- class dxctx3
- {
- public static void main(String[] args)
- {
- rec r = new rec;
- new Thread (new intl(r)).start();
- new Thread (new outou(r)).start();
- }
- }
复制代码 |