A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 妖妖 中级黑马   /  2015-3-21 16:29  /  1083 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

class Res
{
        private String name;
        private int cout=1;
        private boolean flag=false;
        public synchronized void set(String name)
        {               
                while (flag)
                {
                        try
                        {
                                this.wait();
                        }
                        catch (Exception e)
                        {
                        }
                }
                this.name=name+"----------------"+cout++;
                System.out.println(Thread.currentThread().getName()+"I am a e"+this.name);
                flag=true;
                this.notifyAll();
        }
        public synchronized void out()
        {
                while (!flag)
                {
                        try
                        {
                                this.wait();
                        }
                        catch (Exception e)
                        {
                        }
                }               
                System.out.println(Thread.currentThread().getName()+"I am an d"+"\t"+this.name);       
                flag=false;
                this.notifyAll();
        }
}
class Pro implements Runnable
{
        private Res r;
        Pro(Res r)
        {
                this.r=r;
        }
        public void run()
        {
                while (true)
                {
                        r.set("mao");
                }
        }
}
class Con implements Runnable
{
        private Res r;
        Con(Res r)
        {
                this.r=r;
        }
        public void run()
        {
                while (true)
                {
                        r.out();
                }
        }
}
class ThreadDmeo4
{
        public static void main(String[] args)
        {
                Res r=new Res();
                new Thread(new Pro(r)).start();
                new Thread(new Pro(r)).start();
                new Thread(new Con(r)).start();
                new Thread(new Con(r)).start();
        }
}

编译不过,出现了错误,而且是一堆乱码,第一次看见乱码的错误,求指点?


错误提示.png (5.57 KB, 下载次数: 8)

错误提示.png

1 个回复

倒序浏览
为甚没有回答啊,自己顶一下,难道大家看到这么奇葩的错误,大家都不纳闷吗?
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马