Thank you so much. I will study your code. I post my Java solution to 3 as my complements. Comments are welcome.

jabber (jabber)
本文发表在 rolia.net/zh 相约加拿大网上社区枫下论坛
import java.util.*;
import java.io.*;

public class ThreadDemo {
PipedOutputStream pos = null;
PipedInputStream pis = null;
DataInputStream dis = null;
DataOutputStream dos =null;
boolean shouldRun=true;

//use the so-called inner class mechanism
Thread t1= new Thread(){
int n=0;
public void run() {
while(shouldRun){
n++;
if(n%50 ==0) {
try{
dos.writeInt(n);
} catch(IOException e) {};
}
Thread.yield();
}
}
};

//use the so-called inner class mechanism
Thread t2= new Thread(){
public void run() {
while(shouldRun){
try{
System.out.println(dis.readInt());
} catch(IOException e) {};
Thread.yield();
}
}
};

public void stop() {
shouldRun=false;
}

public ThreadDemo() throws IOException{
//Piping IO Streams between two Threads
pos = new PipedOutputStream();
pis = new PipedInputStream(pos);
dis = new DataInputStream(pis);
dos = new DataOutputStream(pos);
t1.start();
t2.start();
}

public static void main(String[] args) throws Exception {
ThreadDemo demo = new ThreadDemo();
}


}
更多精彩文章及讨论,请光临枫下论坛. 网址: rolia.net/zh
(#88563@0)
2001-6-2 -05:00

回到话题: Computer Jobs need true skills----see these assignments, please

回到论坛: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论

URL:   
http://www.rolia.net/zh/post.php?f=0&p=88563