
Signature
# You can't run away. Everyone's connected.
# Marek Puchalski
# Proud linux user: 409592
This was sample code I typed in here. Please assume that the exceptions are
caught etc. printStatus is very simple:
public void printStatus() {
// some system.out of thread's state variables...
}
Thanks
-- padhu
>> public void printWorkerStatus() {
>> while ( t1.isAlive() || t2.isAlive() ) {
[quoted text clipped - 11 lines]
>
> Marek
Marek Puchalski - 08 Mar 2006 15:32 GMT
> This was sample code I typed in here. Please assume that the exceptions are
> caught etc. printStatus is very simple:
>
> public void printStatus() {
> // some system.out of thread's state variables...
> }
It's a pain to try to find bugs in a sample code. See this. It works fine.
class WorkerThread extends Thread
{
public void run()
{
while ( true )
;
}
public void printStatus()
{
System.out.println( 111 );
}
}
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
try
{
Thread.sleep( 40 * 1000 );
}
catch ( InterruptedException e )
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
and the output is like:
print
111
111
111
111 (...)
Hope this helps.
Marek

Signature
# You can't run away. Everyone's connected.
# Marek Puchalski
# Proud linux user: 409592
Oliver Wong - 08 Mar 2006 18:14 GMT
> This was sample code I typed in here. Please assume that the exceptions
> are caught etc. printStatus is very simple:
[quoted text clipped - 4 lines]
>
> Thanks
If I assume you've done everything correctly, then yes, your code works
perfectly. Since it's not working perfectly, perhaps the assumption that
you've done everything correctly is invalid.
Please post an SSCCE. http://mindprod.com/jgloss/sscce.html
- Oliver