Class Send implements Runnable{pipedoutputstream pos = Null;public Send () {this.pos = new PipedOutputStream ();} Public PipedOutputStream Getpipedoutputstream () {return this.pos;} @Overridepublic void Run () {//TODO auto-generated method stub string str = "Hello world!!!"; try {this.pos.write (str.getbytes ());} catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();} try {this.pos.close ();} catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();}} Class Receive implements Runnable{pipedinputstream PiS = Null;public Receive () {This.pis = new PipedInputStream ();} Public PipedInputStream Getpipedinputstream () {return this.pis;} @Overridepublic void Run () {//TODO auto-generated method stub byte b[] = new Byte[1024];int len = 0;try {len = This.pis.read (b);} catch (IO Exception e) {//TODO auto-generated catch block E.printstacktrace ();} try {this.pis.close ();} catch (IOException e) {//TODO auto-generated catch block E.printstacktrace ();} System.out.println (New String (B,0,len));}} public class Pipedoutputstreamdemo {public static void main (string[]args) throws Exception {//TODO auto-generated method stub send send = new Send (); Receive REC = new receive (); Send.getpipedoutputstream (). Connect (Rec.getpipedinputstream ()); new Thread (send). Start () ; New Thread (REC). Start ();}}
Java: Pipeline flow (inter-thread pipeline flow)