//我用的eclipsepackage Chapter10; //这里有提示说A class file was not written......然后就无法run,请问是为什么?下面的代码都没报错了。public class producor { public static void main(String[] args) {
quantity q=new quantity();
new Pro(q);
new con(q);
System.out.println("a a a");
}}
class quantity
{
int n;
boolean b=false;
synchronized int get()
{
if(!b)
try{
wait();
}catch(InterruptedException e){
System.out.println("catch");
}
System.out.println("a"+n);
b=false;
notify();
return n;
}
synchronized void put(int n)
{
if(b)
try
{
wait();
}catch(InterruptedException e){
System.out.println("put errors");
}
this.n=n;
b=true;
System.out.println("put"+n);
notify();
}
}
class Pro implements Runnable
{
quantity q;
Pro(quantity q)
{
this.q=q;
new Thread(this,"Pro").start();
}
public void run() {
int i=0;
while(true)
{
q.put(i++);
}
}
}
class con implements Runnable
{
quantity q;
con(quantity q)
{
this.q=q;
new Thread(this,"con").start();
}
public void run()
{
while(true)
{
q.get();
}
}
}
quantity q=new quantity();
new Pro(q);
new con(q);
System.out.println("a a a");
}}
class quantity
{
int n;
boolean b=false;
synchronized int get()
{
if(!b)
try{
wait();
}catch(InterruptedException e){
System.out.println("catch");
}
System.out.println("a"+n);
b=false;
notify();
return n;
}
synchronized void put(int n)
{
if(b)
try
{
wait();
}catch(InterruptedException e){
System.out.println("put errors");
}
this.n=n;
b=true;
System.out.println("put"+n);
notify();
}
}
class Pro implements Runnable
{
quantity q;
Pro(quantity q)
{
this.q=q;
new Thread(this,"Pro").start();
}
public void run() {
int i=0;
while(true)
{
q.put(i++);
}
}
}
class con implements Runnable
{
quantity q;
con(quantity q)
{
this.q=q;
new Thread(this,"con").start();
}
public void run()
{
while(true)
{
q.get();
}
}
}
解决方案 »
- java 网络编程 关于套接字 服务器与客服端的通讯问题
- 关于Boolean传值的一个问题,不明白?大家帮助一下!
- split()用|,为什么分割不了,应该怎么办?
- 急!请高手帮忙!在线等!
- 关于数组的一个简单问题~
- a==b,a.equals(b)有和区别?
- 两个大阶乘相除溢出。急救。
- 几个多线程编程的概念(菜鸟问)
- 关于visual age for java 和 websphere
- 高分请教!在applet中的远程数据库访问问题!
- 如何获得网页中指定的文本的字号?(100分)
- 【新手提问】一个折磨了我两天整的问题,拿出一半家产出来求救.为什么JScrollPane放在本内的JFrame和JPanel里可以显示.返回给别的类不行
producor.java吗?
放在了
src/Chapter10/目录下面吗?
在thread\bin\Chapter10这个目录下少一个CLASS文件,就是con类的,不知道为什么没出来,请问这是为什么?要怎么改?
少了一个CLASS文件也可以运行么?但是ECLIPSE是报错了。
Exception in thread "main" java.lang.NoClassDefFoundError: Chapter10/con
at Chapter10.producor.main(producor.java:8)
Caused by: java.lang.ClassNotFoundException: Chapter10.con
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 1 more
put0
con 改成其他的名字,比如mycon 就可以了!我再去查一下为什么这样!
所以,不能再windows下面创建名字为con/Con,CON 的类!哈哈哈!我都忘了这个问题了,还有一些其他的类名也不能建立con是操作系统保留的一个设备名字,还有很多设备名都不能拿来用,如下:
The following reserved device names cannot be used as the name of a file: CON, PRN, AUX, CLOCK$, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed by an extension (for example, NUL.tx7).