Java Reference
In-Depth Information
}
}
class CountThread extends Thread
{
int pause;
public void run()
{
for (int i=0; i<5; i++)
{
try
{
System.out.println(i);
pause=(int)(Math.random()*3000);
sleep (pause);
}
catch (InterruptedException interruptEx)
{
System.out.println(interruptEx);
}
}
}
}
An example of this program's output is shown below (Fig. 3.2 ).
Fig. 3.2
Example output from the ThreadHelloCount program
Search WWH ::




Custom Search