Hi everyone,

I hope you are all fine and live happy and safely. This is the first time to post here in the forum, and I feel that there is a nice and variety developers community here. I really appreciate and willing to share with you some of my experience and knowledge. By the way, my English is second language, so if you misunderstand me please let me know.

Currently, I am working in designing and implementing a Filter-and-Pipe architecture for Word document. I stuck with implementing the pipe class. My classes looks like;

Filter class
Pipe class

Class A extends Filter implements Runnable
Class B extends Filter implements Runnable
Class C extends Filter implements Runnable
Class D extends Filter implements Runnable

Class A: read a txt file line by line and SEND it to Class B.
Class B: read the line coming from A, processing it and SEND it to Class C.
Class C: read the line coming from B, processing it and SEND it to Class D.
Class D: read the line coming from C, processing it and print it out.

each of these classes should run in its own thread. Each Filter should wait if there is no data ready. once it ready, should the sender notify the receiver.

I have implement the classes and stuck with the pipe. I don't know how to send the processed line to the next Filter.

Here are what I have done;
public class Filter {  
    Pipe _dataINPipe;  
    Pipe _dataOUTPipe;  
    public String getData(){  
        return _dataINPipe.dataOUT();  
    public void sendData( String tempData){  
class Pipe{  
    Queue<String> _inData = new LinkedList<String>();  
    public void dataIN (String in){  
    public String dataOUT (){  
        return _inData.poll();  
The main class create all objects;
Pipe p1 = new Pipe();  
Pipe p2 = new Pipe();  
Pipe p3 = new Pipe();  
Pipe p4 = new Pipe();  
//// A a1 = new A(null,p1) null refer to inPipe, and p1 refer to outPipe  
A a1 = new A(null,p1);  
B b1 = new B(p1,p2);  
C c1 = new C(p2,p3);  
D d1 = new D(p3,null);  
Thread th1 = new Thread( a1 );  
Thread th2 = new Thread( b1 );  
Thread th3 = new Thread( c1 );  
Thread th4 = new Thread( d1 );  
When I run the project, I notice that the Class D run and stop before it gets all data to print it out. This is because of the class D check if the queue is empty. If True, it will stop processing and stop the thread.

For example, the txt file has 10 line. Class D will stop after line 4 because the Class C takes time to process line 3 and can not pass data to the queue for class D.

I hope you understand the issue. I need your help if you have any idea.