下面是我的代码,因为java被我卸载了,所以无法运行,谁能帮我看看我这个程序编的对吗?
public class ConsumerThread extends Thread{
private BufferReader br;
private boolean running;
public ConsumerThread() {
br = null;
running = true;
}
public void set_running(boolean flag) {
running = flag;
}
public void run() {
while(running)
{
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
num++;
}
}
public static void main(String[] argc)
{
ConsumerThread ct = new ConsumerThread();
ct.start();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
BufferReader b=new BufferReader(new InputStreadReader(System.in));
System.out.println("num="+num);
ct.set_running(false);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
}
}







回复时引用此篇文章
书签