public Counter( String threadName )
{
super( threadName
); // What
if we omitted this line?
System.out.println(
this );
start();
// Could we have started it in Client?
}
// override
Thread's run method
public void run()
{
try
{
while ( currentValue < 5 )
{
System.out.println( getName() + ": " + ( currentValue++ ) );
Thread.sleep( 500 );
}
}
catch ( InterruptedException
e )
{
System.out.println( getName() + " interrupted." );
}
System.out.println(
"Exit from " + getName() + "." );
}
public int getValue()
{
return currentValue;
}
}
public class Client
{
public static void main( String args[] )
{
Counter counterA
= new Counter( "Counter A" );
System.out.println(
"Exit from Main Thread." );
}
}