thread priority question...



JDK 1.4 on WinXP. I have 2 threads started from the main thread. I would
like to print some status of the child threads from the main thread
periodically. But I dont see the main thread to print out anything when the
child threads are running. The child threads do sleep after some work.
Instead should I make the child threads wait() and make the main thread
notifyAll() after printing ?

public class MainThread {
WorkerThread t1, t2;
public static void main(String[] args) {
new MainThread().start();
}

public void start() {
t1 = new WorkerThread();
t2 = new WorkerThread();
t1.start();
t2.start();
// even this is not printed...
System.out.println("print");
printWorkerStatus();
}

public void printWorkerStatus() {
while ( t1.isAlive() || t2.isAlive() ) {
t1.printStatus(); // this print never happens
t2.printStatus(); // this print never happens
Thread.sleep(40*1000);
}
}
}


.



Relevant Pages

  • Re: thread priority question...
    ... It doesnt need to implement Runnable. ... WorkerThread the same way your program executes sequentially and therefore ... like to print some status of the child threads from the main thread ... public void printWorkerStatus() { ...
    (comp.lang.java)
  • Re: thread priority question...
    ... The MainThread is not properly coded to be a Thread - it does not ... WorkerThread the same way your program executes sequentially and therefore ... like to print some status of the child threads from the main thread ... public void printWorkerStatus() { ...
    (comp.lang.java)