请教各位 我的线程wait()了 为什么还继续运行???(100分)
import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer
{
ServerSocket ssoc=null;
LinkedList<String> rlist=new LinkedList<String>();
LinkedList<String> slist=new LinkedList<String>();
Vector<OutputStream> outs=new Vector<OutputStream>();
public ChatServer() throws Exception
{
ssoc=new ServerSocket(9999);
System.out.println("Server 已经启动!");
while(true)
{
Socket soc=ssoc.accept();
new ServerReceive(soc,rlist,slist).start();
new ServerSend(soc,slist,outs).start();
outs.add(soc.getOutputStream());
System.out.println("一个用户已经连接");
}
}
public static void main(String [] args) throws Exception
{
new ChatServer();
}
}
class ServerReceive extends Thread
{
Socket soc=null;
LinkedList<String> rlist=null;
InputStream in=null;
BufferedReader bin=null;
LinkedList<String> slist=null;
public ServerReceive(Socket soc,LinkedList<String> rlist,LinkedList<String> slist) throws Exception
{
this.soc=soc;
this.rlist=rlist;
in=soc.getInputStream();
this.slist=slist;
bin=new BufferedReader(new InputStreamReader(in));
new Thread(new Runnable()
{
public void run()
{
try
{
read();
System.out.println("*********1");
}
catch(Exception ex){}
}
}).start();
}
public void read() throws Exception
{
String line=null;
while((line=bin.readLine())!=null)
{
rlist.add(line);
}
this.notifyAll();
}
public void run()
{
while(true)
{
String str=this.getMessage();
slist.add(str);
System.out.println("*********2");
}
}
public String getMessage()
{
while(rlist.size()<=0)
{
try
{
wait();
}
catch(Exception ex){}
System.out.println("*********3");
}
return rlist.removeFirst();
}
}
class ServerSend extends Thread
{
Socket soc=null;
OutputStream out=null;
PrintWriter pout=null;
LinkedList<String> slist=null;
Vector<OutputStream> outs=null;
public ServerSend(Socket soc,LinkedList<String> slist,Vector<OutputStream> outs) throws Exception
{
this.soc=soc;
this.outs=outs;
this.slist=slist;
out=soc.getOutputStream();
pout=new PrintWriter(out,true);
}
public void sendMessage(String message)
{
for(OutputStream out:outs)
{
if(out==null)
{
outs.remove(out);
System.out.println("not Message");
}
else
{
new PrintWriter(out,true).println(message);
}
}
}
public String getMessage()
{
while(slist.size()<=0)
{
try
{
wait(); //为什么wait了 现成还在运行???
}
catch(Exception ex){}
System.out.println("*********4");
}
return slist.removeFirst();
}
public void run()
{
while(true)
{
String mes=this.getMessage();
System.out.println("*********5");
this.sendMessage(mes);
}
}
}
在3和4还能运行 大家可以用telnet测试 为什么呀 请各位帮忙 解决马上给分