java多线程

来源:互联网 发布:淘宝低价卷 编辑:程序博客网 时间:2024/06/14 10:55

原文地址

线程简介
这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

public class PipedTest {    static class Print implements Runnable {        private PipedInputStream in;        public Print(PipedInputStream in) {            this.in = in;        }        @Override        public void run() {            int receive = 0;            try {                while ((receive = in.read()) != -1) {                    System.out.println(receive);                }            } catch (IOException ex) {                ex.printStackTrace();            }        }    }    /**     * @param args     */    public static void main(String[] args) throws Exception {        PipedOutputStream out = new PipedOutputStream();        PipedInputStream in = new PipedInputStream();        // Out ==> In        out.connect(in);//这个connect的方法连接输入输出流        Thread t = new Thread(new Print(in));        t.start();        int receive = 0;        while ((receive = System.in.read()) != -1) {            out.write(receive);        }    }}
0 0
原创粉丝点击