Re: thread priority question...
- From: "Padhu Vinirs" <prabha_pady@xxxxxxxxxxx>
- Date: Sun, 12 Mar 2006 19:38:09 -0500
The main thread is the starting class ( with the main method ). That is the
default thread. It doesnt need to implement Runnable. My question was
related to the main thread being able to print status of threads it started.
-- padhu
"Dobromir Gaydarov" <notme@xxxxxxxxxxxx> wrote in message
news:u7XPf.3149$xM2.237984@xxxxxxxxxxxxxxxxxxxxxxxx
The MainThread is not properly coded to be a Thread - it does not
impletement the java.lang.Runnable interface. If we assume you coded the
WorkerThread the same way your program executes sequentially and therefore
you will see your output from the main "thread" as soon as the child
"threads" complete.
Regards,
Dobromir
"Padhu Vinirs" <prabha_pady@xxxxxxxxxxx> wrote in message
news:CuSdnTtRE9a4WZPZRVn-qQ@xxxxxxxxxxxxxx
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);
}
}
}
.
- References:
- thread priority question...
- From: Padhu Vinirs
- Re: thread priority question...
- From: Dobromir Gaydarov
- thread priority question...
- Prev by Date: Re: Java Gurus Help
- Next by Date: Re: Java Gurus Help
- Previous by thread: Re: thread priority question...
- Next by thread: Java vs Flash
- Index(es):
Relevant Pages
|
|