Problem with threads

Hi,

I am facing some issues with the multithreading.

I have 3 class extending threads (say class1,2,3)

Class 1 starts its thread and inside the run() it starts the other two thread.

Two vectors are shared between these class

Verctor1 - Thread1 (class1) and Thread2 (class2)

Verctor2 - Thread1 (class1) and Thread3 (class2)

public class1 {

public void run() {

class2 c2;

class3 c3;

while(true) {

//if no line to read then continue

//Read a line from a file

//Add the line to vector

if(c2.isSleeping() == 1)

c2.startProcessing();

if(c3.isSleeping() == 1)

c3.startProcessing();

}

}

}

public class2 {

public void run() {

//Some work

if(vector1.size() == 0)

holdProcessing();

//Some work

}

public synchronized void startProcessing(){

notify();

slept = false;

}

private synchronized void holdProcessing(){

try {

slept = true;

wait();

} catch (InterruptedException e){

e.printStackTrace();

}

}

public synchronized boolean isSleeping(){

return slept;

}

}

public class3 {

public void run() {

//Some work

if(vector2.size() == 0)

holdProcessing();

//Some work

}

public synchronized void startProcessing(){

notify();

slept = false;

}

private synchronized void holdProcessing(){

try {

slept = true;

wait();

} catch (InterruptedException e){

e.printStackTrace();

}

}

public synchronized boolean isSleeping(){

return slept;

}

}

The thread1 will get data from a file, which is inturn periodically updated by another process.

Thread 1 will sleep for 10 sec if there is no data to read. If thread1 got any data to read it will read a line and add it to vector 1 and 2 and notify thread 2 and 3.

But in few cases even after thread 2 and 3 got notified its in state of sleep and not taking any data from the vector.

Can any one help me to fix this?

[2161 byte] By [Fred_1kinga] at [2007-11-26 23:44:01]
# 1
Are you doing this:if(c2.isSleeping() == 1)c2.startProcessing();if(c3.isSleeping() == 1)c3.startProcessing();only when you read from file or in each class1 thread loop ?
abc0xyza at 2007-7-11 15:14:59 > top of Java-index,Java Essentials,Java Programming...
# 2
Sorry its if(c2.isSleeping())c2.startProcessing();if(c3.isSleeping())c3.startProcessing();
Fred_1kinga at 2007-7-11 15:14:59 > top of Java-index,Java Essentials,Java Programming...
# 3

At a point of time if there is no elements in file and there is no elements in vector then both the thread2 and 3 will go to wait() and thread 1 sleeps for 10 sec. if thread 1 got any line in the file to process then it read it, write it to vector and notify the thread 2 and 3 if they r sleeping.

Fred_1kinga at 2007-7-11 15:14:59 > top of Java-index,Java Essentials,Java Programming...