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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 邓熊财 中级黑马   /  2015-3-23 11:24  /  850 人查看  /  12 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

class Jub
{
        String name;
         String age;
         boolean nn;

}
class Abs implements Runnable
{
        Jub s;
        Abs(Jub s)
        {
                this.s = s;
        }
        public void run()
        {
                int x = 0;
                while(true)
                {
                        synchronized(s)
                        {        if(s.nn)try{s.wait();}catch(Exception e){}//等待机制
                                {
                                        if (x==0)
                                        {       
                                                s.name = "nsss";
                                                s.age = "bhddhhd";
                                        }else
                                        {
                                                s.name = "丽丽";
                                                s.age = "女女女";
                                        }
                                        x = (x+1)%2;
                                        s.nn=true;
                                        s.notify();
                                }
                        }
                }
        }
}
class Diao implements Runnable
{
        Jub s;
        Diao(Jub s)
        {
                this.s = s ;
        }
        public void run()
        {       
                while(true)
                {        synchronized(s)
                        {        if (!s.nn)try{s.wait();}catch(Exception e){}
                                {
                                        System.out.println(s.name+"......"+s.age);
                                        s.nn = false;
                                        s.notify();
                                }
                        }
                }
        }
}
class Day0802
{
        public static void main(String [] args)
        {        Jub s = new Jub();
                Abs a = new Abs(s);
                Diao b = new Diao(s);
                Thread t1 = new Thread(a);
                Thread t2= new Thread(b);
                t1.start();
                t2.start();

        }
}

12 个回复

倒序浏览
帮我看看问题出在哪了谢谢各位了
回复 使用道具 举报
没问题啊
回复 使用道具 举报
可是运行不了
回复 使用道具 举报
能运行。你是什么错误?是不是你编译的时候文件名写错了,或者运行的时候。
回复 使用道具 举报
---------- java ----------
java.lang.NoClassDefFoundError: Day0802/
Caused by: java.lang.ClassNotFoundException: Day0802.
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: Day0802..  Program will exit.
Exception in thread "main"
输出完成 (耗时 0 秒) - 正常终止     这是我的错误提示
回复 使用道具 举报
你用的什么编译器?
回复 使用道具 举报
Editpius这个
回复 使用道具 举报
我查了一下API这个异常,如果你在运行类名没有输错的话,就是你的环境变量配置错误了。我还是建议你在编译时好好检查一下你的类名。
javac 文件名.class    编译
java Day0802         运行
如果还是错误的话,就请你检查一下你的变量配置问题
回复 使用道具 举报
好的谢谢

回复 使用道具 举报
运行错误提示是什么?
回复 使用道具 举报
存储路径有问题吧
回复 使用道具 举报
果断用命令行去看
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马