package com.xuan.thread;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;
class ReaderThread extends Thread{
private PipedReader pr;
//用于包装管道流的BufferReader对象
private BufferedReader br;
public ReaderThread(){}
public ReaderThread(PipedReader pr){
this.pr=pr;
this.br=br;
}
public void run(){
String buf=null;
try {
//逐行读取管道输入流中的内容
while((buf=br.readLine())!=null){
System.out.println(buf);
}
} catch (IOException e) {
e.printStackTrace();
}finally{
try{
if(br!=null){
br.close();
}
}catch(IOException e){
e.printStackTrace();
}
}
}
}
class WriterThread extends Thread{
String[] books=new String[]{"struts2权威","ROR敏捷开发指南","基于J2EE的Ajax宝典","轻量级J2EE企业应用指南"};
private PipedWriter pw;
public WriterThread(){}
public WriterThread(PipedWriter pw){
this.pw=pw;
}
public
(47)使用管道流进行线程间的通信
最新推荐文章于 2020-01-23 14:42:36 发布