本帖最后由 葛奎 于 2012-6-24 12:55 编辑
- class Res
- {
- private boolean flag=false;
- private String name;
- private int count=1;
- public synchronized void proSom(String name)
- {
- //while(false)
- this.name=name;
- System.out.println(Thread.currentThread().getName()+"生产者..."+count+++this.name);
- }
- public synchronized void conSom()
- {
- //while(true)
- System.out.println(Thread.currentThread().getName()+"消费者................"+count+++this.name);
- }
- }
- class Pro implements Runnable
- {
- private Res r;
- Pro(Res r)
- {
- this.r=r;
- }
- public void run()
- {
- while(true)
- r.proSom("+商品+");
- }
- }
- class Con implements Runnable
- {
- private Res r;
- Con(Res r)
- {
- this.r=r;
- }
- public void run()
- {
- while(true)
- r.conSom();
- }
- }
- class ProConDemo
- {
- public static void main(String[] args)
- {
- Res r=new Res();
- Con c=new Con(r);
- Pro p=new Pro(r);
- Thread t1=new Thread(c);
- Thread t2=new Thread(p);
- t1.start();
- t2.start();
- }
- }
复制代码 编译能通过,怎么运行时候就出现了错误
Exception in thread "main" java.lang.NoClassDefFoundError: Con |
|