Java: Pipeline flow (inter-thread pipeline flow)

Source: Internet
Author: User
Tags stub

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.