Java一个线程的问题
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!