Source Code : PipedReader and PipedWriter and thread
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
PipedReader and PipedWriter and thread
import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;
class MyThread extends Thread {
private PipedReader pr;
private PipedWriter pw;
MyThread(String name, PipedReader pr, PipedWriter pw) {
super(name);
this.pr = pr;
this.pw = pw;
}
public void run() {
try {
if (getName().equals("src")) {
for (int i = 0; i < 15; i++)
pw.write("src " + " A" + i + "
");
pw.close();
} else {
int item;
while ((item = pr.read()) != -1)
System.out.print((char) item);
pr.close();
}
} catch (IOException e) {
}
}
}
class PipedThreads {
public static void main(String[] args) throws Exception {
PipedWriter pw = new PipedWriter();
PipedReader pr = new PipedReader(pw);
MyThread mt1 = new MyThread("src", pr, pw);
MyThread mt2 = new MyThread("dst", pr, pw);
mt1.start();
Thread.sleep(2000);
mt2.start();
}
}
Thank with us