Java一个线程的问题

wlfjck 2001-03-02 03:10:00
import java.io.*;

public class mailsvr
{

private static String s_ConSign = "<console>:";


private static String SYS_INSTRUCTION_QUIT = "QUIT";
private static String SYS_INSTRUCTION_EXIT = "EXIT";
private static String SYS_INSTRUCTION_HELP = "HELP";
private static String SYS_INSTRUCTION_START = "START";

private static String SYS_ERROR_COMMAND = "Invalid Command";


public static void main(String[] args)
{
DataInputStream conStream=
new DataInputStream (
new BufferedInputStream
( System.in ) );

String s_Inbuf="";

boolean b_Quit=false;

Thread threadMail;

threadMail=new Thread(new clsmail(),"test Thread");

try
{
while(!b_Quit)
{
System.out.print(s_ConSign);
s_Inbuf=conStream.readLine();
if (s_Inbuf.equalsIgnoreCase(SYS_INSTRUCTION_QUIT))
{
clsmail.b_run=false;
b_Quit=true;
}
else if(s_Inbuf.equalsIgnoreCase(SYS_INSTRUCTION_EXIT))
{
clsmail.b_run=false;
b_Quit=true;
}
else if(s_Inbuf.equalsIgnoreCase(SYS_INSTRUCTION_START))
// do start operation
{

threadMail.start();
}

}
}
catch( IOException E)
{
E.printStackTrace();
}

return;
}
}

class clsmail implements Runnable
{
public static boolean b_run;


public clsmail()
{
try
{
b_run=true;
}
catch(Exception E)
{
E.printStackTrace();
}

}


public void run()
{

int i=0;
while(b_run)
{
try
{
/******************************************
*******************************************
if i add
System.out.println("yeah");
in here ,this program will
exit normally!
but if i don't,this program will trap in
dead cycle!
what's wrong with my program!
please help me,thanks lot!
******************************************
*****************************************/
i++;


}
catch(Exception E)
{
E.printStackTrace();
}
}
System.out.println("I ma exit");
}
}


program list above is mine,but when i run it in sun jdk1.2
enviroment,it will not finished normally!

my step list below:
(console):start
(console):quit
just at when i typed "quit",this program will trap in dead cycle!
what's wrong!!
thanks very much!
...全文
145 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlfjck 2001-03-03
  • 打赏
  • 举报
回复
我已经找到解决的办法,但是还有一些东西不明白,希望和高手探讨
wlfjck 2001-03-03
  • 打赏
  • 举报
回复
一群笨蛋,其实这是线程调度的问题,回去看书去吧,有没有真正的高手!
怎么全都是弱智儿童!
wlfjck 2001-03-03
  • 打赏
  • 举报
回复
起死我了!Java高手呢!
程序员不是耍嘴皮子的!是靠实力的,耍嘴皮子的人不配在这儿!
一般玩去
wlfjck 2001-03-03
  • 打赏
  • 举报
回复
而且,我还要说,笨蛋,反编译Java的Class的结果是Java源程序,怎么能看到编译后的代码!
要看编译后的代码其实就是class文件。你懂不懂Java,笨蛋!一边玩去!
burntorun 2001-03-03
  • 打赏
  • 举报
回复
是你在寻求帮助是吧,我们想帮助你解决问题,即使说的可能不对但我们是真心诚心的。但你却出口伤人,如果连做人都不会,成为所谓的高手还有什么意义。
burntorun 2001-03-02
  • 打赏
  • 举报
回复
检查一下,你的编译设置,把optimize去掉。
我怀疑是有可能打开优化开关后,如果未加System.out.println("yeah")这句时,编译器做了某些优化,加了这句话后编译器就不在优化。最好用反编译看看编译后的代码。
wlfjck 2001-03-02
  • 打赏
  • 举报
回复
no,if you run in jdk1.2 enviroment,you will find some problems!
could you tell what's wrong!
lmy2000 2001-03-02
  • 打赏
  • 举报
回复
i run it in jdk1.3 normally.
no problem!
maybe something wrong with your environment

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧