综合问题~急~~
编译时候没有问题,运行时候 停在run()不动了 请大家帮我看看
import java.io.*;
public class ThreadDoctors implements Runnable
{
private String name;
private PipedInputStream sin;
private PipedOutputStream sout;
ThreadDoctors(String name,PipedInputStream sin,PipedOutputStream sout)
{
this.name = name;
this.sin = sin;
this.sout = sout;
}
public void talks(InputStream in,OutputStream out) throws IOException
{
BufferedReader rd = new BufferedReader(new InputStreamReader(in));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out),true);
pw.println("Hello!");
while(true)
{
String question = rd.readLine();
reply(pw,question);
}
}
private void reply(PrintWriter pw ,String question) throws IOException
{
pw.println(name+":"+question);
}
public static void main(String[] args) throws IOException
{
PipedInputStream sin1 = new PipedInputStream();
PipedOutputStream sout1 = new PipedOutputStream(sin1);
PipedInputStream sin2 = new PipedInputStream();
PipedOutputStream sout2 = new PipedOutputStream(sin2);
ThreadDoctors dr1 = new ThreadDoctors("wang",sin1,sout2);
ThreadDoctors dr2 = new ThreadDoctors("zhang",sin2,sout1);
Thread t1 = new Thread(dr1);
Thread t2 = new Thread(dr2);
//dr.talks(System.in,System.out);
t1.start();
t2.start();
}
public void run()
{
try
{
talks(sin,sout);
}
catch(IOException e){};
}
}