Java Reference
In-Depth Information
public void run()
{
int pause;
for (int i=0; i<10; i++)
{
try
{
System.out.println(
getName()+" being executed.");
pause = (int)(Math.random()*3000);
sleep(pause); //0-3 seconds.
}
catch (InterruptedException interruptEx)
{
System.out.println(interruptEx);
}
}
}
}
Example output from the above program is shown in Fig. 3.1 below.
Fig. 3.1
Example output from the ThreadShowName program
Search WWH ::




Custom Search