public int getValue()
{
return
currentValue;
}
}
public
class Client
{
public static void main( String args[] )
{
Counter counterA
= new Counter( "Counter A" );
try
{
int val;
do
{
val = counterA.getValue();
System.out.println( "Main Thread: " + val );
Thread.sleep( 1000 );
}
while ( val < 5 );
}
catch ( InterruptedException ignore
) {
}
System.out.println(
"Exit from Main Thread: Counter = " + counterA.getValue() );
//
Client accesses counterA.CurrentValue after worker thread has died.
// worker thread is dead but not garbage.
}
}